Skip to content

Instantly share code, notes, and snippets.

@AhmedHelalAhmed
Created December 2, 2017 20:40
Show Gist options
  • Save AhmedHelalAhmed/8903b3ed69afdacc3bb14bc61af9575d to your computer and use it in GitHub Desktop.
Save AhmedHelalAhmed/8903b3ed69afdacc3bb14bc61af9575d to your computer and use it in GitHub Desktop.
Stack
#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