This program demonstrates stack operations using an array data structure. It presents a menu to allow the user to perform push, pop, peep, change, status, and display operations on the stack. The stack object uses methods like push(), pop(), peep(), change(), status(), and display() to add/remove elements, view elements, modify elements, check status, and output the stack. The program provides a loop to continuously get user input and perform the selected operation until the user chooses to exit.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
27 views2 pages
#Define #Define: Void Int While
This program demonstrates stack operations using an array data structure. It presents a menu to allow the user to perform push, pop, peep, change, status, and display operations on the stack. The stack object uses methods like push(), pop(), peep(), change(), status(), and display() to add/remove elements, view elements, modify elements, check status, and output the stack. The program provides a loop to continuously get user input and perform the selected operation until the user chooses to exit.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2
20.
//program to show stack operation using array
#include <iostream.h> #include <conio.h> #define MAX 10 #define MIN 0 void main(){ int choice; stack obj; while(1){ clrscr(); cout<<"\t\t 1) PUSH \n"; cout<<"\t\t 2) POP \n"; cout<<"\t\t 3) PEEP \n"; cout<<"\t\t 4) CHANGE \n"; cout<<"\t\t 5) STATUS \n"; cout<<"\t\t 6) DISPLAY \n"; cout<<"\t\t 7) EXIT \n"; cout<<"\t\tEnter your Choice : "; cin>>choice; int item,index; switch(choice){ case 1 : cout<<"\n\n\t\t*****PUSH*****\n"; cout<<"\t\tEnter item to be pushed : "; cin>>item; obj.push(item); break; case 2 : cout<<"\n\n\t\t*****POP*****\n"; item=obj.pop(); if(item!=-111){ cout<<"\n\t\tItem being poped out is : "<<item; getch(); } break; case 3 : cout<<"\n\n\t\t*****PEEP*****\n"; cout<<"\t\tEnter index for item to be peeped : "; cin>>index; item=obj.peep(index); if(item!=-111){ cout<<"\n\t\tItem to be peeped is : "<<item; getch(); } break; case 4 : cout<<"\n\n\t\t*****CHANGE*****\n"; cout<<"\t\tEnter index for item to be changed : "; cin>>index; cout<<"\t\tEnter item value for it : "; cin>>item; obj.change(index,item); break; case 5 : cout<<"\n\n\t\t*****STATUS*****\n"; cout<<"\n\t\tTotal Elements are : "<<obj.status(); getch(); break; case 6 : cout<<"\n\n\t\t*****DISPLAY*****\n"; obj.display(); break; case 7 : gotoout; default: cout<<"\n\n\t\tInvalid Choice\n\n"; getch();break;} } }