Program Of Stack in C++



#include<iostream>
#include<conio.h>

 using namespace std;
  int top=-1,z[5];

  void push(int value)
  {
  if(top==4)
  {
              cout<<"stack is full \n";
  }
  else
  {
              top++;
              z[top]=value;
  }
 
  }
void pop()
{
if(top==-1)
{
            cout<<"stack is empty\n";
}
else
{
            top--;
}
}

void display()
{
            if(top==-1)
            {
             cout<<"noting to display";
            }
            else
            {
            cout<<"array is \n";
            for(int i=0;i<=top;i++)
            {
                        cout<<"\t"<<z[i];
            }
           
            }

}

int main()
{
            int value ,choise;
            do
            {
                        cout<<"\n 1. push \n 2. pop \n 3. display  \n 4. exit \n input choise : ";
                        cin>>choise;
                        if(choise==1)
                        {
                        cout<<"\n enter value\n";
                        cin>>value;
                        push(value);
                        }
                        if(choise==2)
                        {
                        pop();
                        }
            if(choise==3)
            {
            display();
            }
}

            while(choise!=4);
            {
            cout<<"\n Exiting. \n";
            }
           
            getch();
            }


No comments:

Post a Comment