Created
December 2, 2017 20:40
-
-
Save AhmedHelalAhmed/8903b3ed69afdacc3bb14bc61af9575d to your computer and use it in GitHub Desktop.
Stack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
class Stack | |
{ | |
int* ar; | |
int Size; | |
int tos; | |
public: | |
int Gettos(); | |
int push(int d); | |
int pop(); | |
Stack() | |
{ | |
tos=0; | |
Size=10; | |
ar=new int[Size]; | |
} | |
int Getsize() | |
{ | |
return Size; | |
} | |
~Stack() | |
{ | |
delete ar; | |
} | |
}; | |
int main() | |
{ | |
Stack stk; | |
stk=Fillstack(); | |
return 0; | |
} | |
int Stack::pop() | |
{ | |
int retval=-1;//empty stack | |
if(tos>0) | |
{ | |
tos--; | |
retval=ar[tos]; | |
} | |
return retval; | |
} | |
Stack Fillstack() | |
{ | |
Stack st; | |
for(int i=0;i<10;i++) | |
{ | |
st.push(i); | |
} | |
return st; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment