View Single Post
  #1  
Old 16-09-2008, 11:14 PM
shmsa's Avatar
shmsa shmsa is offline
Grown up punk

 
Join Date: Oct 2007
Location: Muslim Town Multan
Posts: 195
Contact Number: 0322-6196713
Program / Discipline: BSIT
Class Roll Number: 07-22
shmsa is a jewel in the roughshmsa is a jewel in the roughshmsa is a jewel in the roughshmsa is a jewel in the rough
lectures Program of STACK

Code:
#include<iostream.h>
void push(int stack[], int &top)
{
 int element;
if (top==4)
cout<<""<<endl;
else
{
 cout<<"enter element to puch in stack===="<<endl;
 cin>>element;
top++;
stack[top]=element;
}
}
void pop(int stack[],int &top)
{
 if (top==-1)
  cout<<"stack is empty"<<endl;
 else
 {
 cout<<"poped element of stack is===="<<stack[top]<<endl;
 top--;
 }
}
void show(int stack[], int &top)
{
 for (int i=top;i>=0;i--)
  cout<<stack[i]<<endl;
}
void main()
{
 char opt='y';
 int stack[5];
 int top=-1;
 while (opt=='y')
 {
  cout<<"enter 'P' for PUSH"<<endl<<"enter 'O' for POP"<<endl<<"enter 'S' for SHOW"<<endl;
  cin>>opt;
  if (opt=='p')
   push(stack,top);
  else
   if (opt=='o')
    pop(stack,top);
   else
   if (opt=='s')
    show(stack,top);
   else
    cout<<"you have entered werong character"<<endl;
   cout<<"DO you want more y/n"<<endl;
   cin>>opt;
 }//end of while
}// end of main

Reply With Quote