Wednesday, September 16, 2009

CPP PROGRAMS

STACK PROGRAM

#include
#include
#include
#define size 5
 

int top=-1;
int item,i;
int s[size];
class stack
{
    int item,i;
    int s[size];
public:
    void push();
    void pop();
    void display();
};
void stack::push()
{
    if(top==size-1)
      {
      cout<<" stack is overflow"<
      }
      else
      {
      cout<<" enter the item to be insert---->";
      cin>>item;
      s[++top]=item;
      }
}
void stack::pop()
{
   if(top==-1)
     {
     cout<<" stack is underflow"<
     }
     else
     {
     cout<<"the deleted item is------------>"<
     s[top--];
     }
}
void stack::display()
{
   if(top==-1)

      {
      cout<<"stack is underflow"<
      }
      else
      {
      cout<<" the stack items are------------>";
      for(i=0;i<=top;i++)
      cout<
      }
}
void main()
{
stack p;
int ch;
clrscr();
while(1)
{
   cout<<"\n 1.push\n 2.pop\n 3.display\n 4.exit\n";
   cout<<" enter ur choice---------------->";
   cin>>ch;
   switch(ch)
     {
     case 1:p.push();
        break;
     case 2:p.pop();
        break;
     case 3:p.display();
        break;
     case 4:exit(0);
     }
}
getch();
}

No comments: