You are on page 1of 2

#include<conio.

h> void main() { clrscr(); int stack[100],loc,top,item,max=100; cout<<"\n------ Stack Insertion using Array ------"; cout<<"\n\nEnter Value of Stack Top : "; cin>>top; if(top>=max) { cout<<"\nStack is Full"; getch(); return; } cout<<"\nEnter Elements in Stack :\n"; for(loc=1;loc<=top;loc++) { cin>>stack[loc]; } ins: cout<<"\nEnter Item you want to Insert : "; cin>>item; top=top+1; stack[top]=item; //Increment the Top //Insert Element

cout<<"\nStack After Insertion :\n"; for(loc=1;loc<=top;loc++) { cout<<stack[loc]<<endl; } cout<<"\nTop : "<<top; cout<<"\n\nItem "<<item<<" is Inserted at Top\n\n"; cout<<"\n\nWant to Insert more elements ?????\n\n"; cout<<" -----> Press 1 to Continue\n"; cout<<" -----> Press any Key to Exit\n"; char choice; cin>>choice; if(choice=='1' && top<max) { cout<<endl<<endl; goto ins; } else if(choice=='1' && top>=max) { cout<<"\nStack is Full"; getch(); return; }

else { return; } }

You might also like