Skip to content

Commit

Permalink
Merge pull request keshavsingh4522#53 from Misbahud-Din/electron
Browse files Browse the repository at this point in the history
Electron
  • Loading branch information
keshavsingh4522 committed Oct 14, 2020
2 parents 0e20f29 + c3cc8aa commit 8f8515d
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
96 changes: 96 additions & 0 deletions CPP/fifo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
Author: Misbahud Din
Topic: First In First Out (FIFO)
Description: Pushing Values to an Empty Array and then poping out those values
*/

#include <iostream>

using namespace std;

class FIFO // Parent Class
{
protected:
int st[5] = {}; // An Empty Array
int top;
int tail;
public:
FIFO(): top(-1), tail(-1)
{
// No arg constructor
}
void push(int var) // Pushing values
{
cout << "Push = " << var << endl;
st[++top] = var;
}
int pop() // Take number off Queue
{
return st[++tail]; // Returns the deleted integer
}
};

class FIFO2 : public FIFO // Child Class
{
public:
FIFO2() : FIFO()
{
// No Arg Constructor of Parent Class
}

void push (int var)
{
if (top == 4) // If stack gets full top = size - 1
{
cout << "Fifo is Full" << endl;
}
else
{
// Calling Parent's function
FIFO::push(var);
}
}
int pop ()
{
if ( top == tail) // When top and tail gets equal it means the stack is empty
{
cout << "Fifo is Empty" << endl;
top = -1; // Setting both values to -1 to use later
tail = -1;
return -1;
}
else
{
// Calling Parent's Function
FIFO::pop();
}
}
};


int main()
{
FIFO2 f;
// Pushing 6 values
f.push(11);
f.push(22);
f.push(33);
f.push(44);
f.push(55);
f.push(66); // Full Condition
// Poping values
cout << f.pop() << endl;
cout << f.pop() << endl;
cout << f.pop() << endl;
cout << f.pop() << endl;
cout << f.pop() << endl;
cout << f.pop() << endl; // Empty array

f.push(88);
f.push(99);

cout << f.pop() << endl;
cout << f.pop() << endl;

return 0;
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ Steps for adding your name below
| Rupali | [@Rupali409](https://github.com/Rupali409) |
| Muhammad Bilal | [@Muhammad-Bilal-MB](https://github.com/Muhammad-Bilal-MB) |
| Sandi Aris | [@Sandi-aris](https://github.com/sandi-aris) |
| Misbahud Din | [@Misbahud-Din](https://github.com/Misbahud-Din) |


---
Expand Down

0 comments on commit 8f8515d

Please sign in to comment.