//Dickens Fenelon

//Data Structure

//Simple Stack Menu:Using Arrays And Functions

 

#include<iostream.h>

 

void push(int mystack[], int &mytop, int item){

     

            mystack[mytop] = item;

              mytop = mytop + 1;

 

}//push function

 

int pop(int mystack[], int &mytop){

           

              mytop = mytop - 1;

              int item = mystack[mytop];

              return item;

 

}//pop function

 

int isempty(int mytop){

                 

              if(mytop==0) return 1;

              else return 0;

 

}//isempty

 

int isfull(int mytop,const int maxstacksize){

 

               if(mytop==maxstacksize) return 1;

               else return 0;

 

}//isfull

 

void main(){

 

              const int maxstacksize = 5;

              int mystack[maxstacksize];

              int mytop,x; char option;

              mytop = 0;//stack top initilization

             

              do  { cout<<"Select One Of The Options:"<<endl;

                          cout<<"1-push  2-pop  3-isempty  4-isfull  5-quit:";

                          cin>>option;

                          switch(option){

 

                          case '1':if(isfull(mytop,maxstacksize))

                                           cout<<"You Can't Push"<<endl;

                                else{cout<<"Enter The Number That Will Be Pushed:";

                                cin>>x;

                                push(mystack,mytop,x);

                                }//else

                                break;

                               

                          case '2': if(isempty(mytop))

                                            cout<<"you Can't pop"<<endl;

                                else{cout<<"The Number Popped Is:"<<pop(mystack,mytop);

                                cout<<endl;

                                }//else

                                break;

 

                          case '3': if(isempty(mytop)==1)

                                            cout<<"Stack Is Empty."<<endl;

                                else cout<<"Stack Is Not Empty."<<endl;

                                break;

 

                          case '4': if(isfull(mytop,maxstacksize)==1)

                                            cout<<"Stack Is Full."<<endl;

                                else cout<<"Stack Is Not Full."<<endl;

                                break;

 

                          case '5': cout<<"Thank You For Using Our Menu!"<<endl;

                                break;

                          default:cout<<"Enter Correct Options"<<endl;

                          }//swich

             

              }while(option!='5');

}//main

 

 

 

Hosted by www.Geocities.ws

1