Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class stackone
- {
- private:
- int *ar;
- int top, siz;
- public:
- stackone()
- {
- top=-1;
- cout<<endl<<"Enter stack size ";
- cin>>siz;
- ar = new int[siz];
- }
- void push(int m)
- {
- if(top==siz-1)
- cout<<endl<<" Stack overflow no push ";
- else
- {
- top++;
- ar[top]=m;
- cout<<endl<<m<<" Push successful ";
- }
- }
- void printTop()
- {
- if(top == -1)
- {
- cout<<"Stack is EMPTY"<<endl;
- }
- else{
- int t = ar[top];
- cout<<"Top value is "<<t<<endl;
- }
- }
- int getSize()
- {
- if(top == -1)
- {
- cout<<"Stack is EMPTY"<<endl;
- }
- else
- {
- int i =0 ;
- for(i=0; i<=top; i++)
- {
- }
- cout<<"Stack size is "<<i<<endl;
- }
- }
- };
- int main()
- {
- stackone *ob = new stackone();
- int choice;
- do
- {
- cout<<endl<<"\t STACK OPERATIONS ";
- cout<<endl<<"1. Push a value ";
- cout<<endl<<"2. Print topmost value ";
- cout<<endl<<"3. Print number of values in stack ";
- cout<<endl<<"Select choice [4 to exit ] ";
- cin>>choice;
- switch(choice)
- {
- case 1:
- int n;
- cout<<"Enter value to push : ";
- cin>>n;
- ob->push(n);
- break;
- case 2:
- ob->printTop();
- break;
- case 3:
- ob->getSize();
- break;
- default:
- cout<<endl<<" give 4 for exit ";
- }
- }
- while(choice !=4);
- cout<<endl<<"Thanks for testing me ";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement