//Dickns Fenelon

//Stack Using Struck

 

#include <iostream.h>

 

struct stack{

      int temp[5];

      int top;

};//Stack

 

void push(stack &mine,int x){

      mine.temp[mine.top] = x;

      mine.top = mine.top + 1;

}//End Push

 

int pop(stack &mine){

      mine.top = mine.top - 1;

      int k = mine.temp[mine.top];

      return k;

}//End Pop

 

int isempty(stack mine){

      if(mine.top == 0)return 1;

      else return 0;

}//End ISEmpty

 

int isfull(stack mine,const int stacksize){

      if(mine.top == stacksize)

            return 1;

      else

            return 0;

}//End ISFull

 

void main(){

           

            stack mine;

            const int stacksize = 5;

            mine.temp[stacksize];

            int x;

            int option;

            mine.top = 0;

           

            do{

           

            cout << "Please enter an option" << endl;

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

            cin  >> option;

 

            switch(option){

 

            case 1:

                  if(isfull(mine,stacksize))

                        cout << "You can't push" << endl;  

                  else{

                        cout << "Enter the number that will be pushed:";

                        cin >> x;

                        push(mine,x); cout << endl;

                  }//End Else

                  break;     

            case 2:

                  if(isempty(mine))

                        cout << "You can't pop" << endl;   

                  else{

                        cout << "The number popped is:" << pop(mine);cout << endl;

                  }//End Else

                  break;

            case 3:

                  if(isempty(mine)==1)

                        cout << "Stack is empty" << endl;

                  else

                        cout << "Stack is not empty" << endl;

                  break;

            case 4:

                  if(isfull(mine,stacksize )== 1)

                        cout << "Stack is full" << endl;

                  else

                        cout << "Stack is not Full" << endl;

                  break;

            case 5: cout << "Good Bye" << endl;

                        cout << "Thank For Using Dickens'Menu!!!!!!!!!!" << endl;

                  break;

           

            default:

                 

                  cout << "Please select the correct option" << endl;

     

            }//End Switch

     

            }while(option != 5);

 

}//End Main

Hosted by www.Geocities.ws

1