C++ code for Stack
#include#include #include using namespace std; int stack[6]; void push(int element); int pop(); string display(); int is_empty(); int element(); int top = -1; int main(int argc, const char * argv[]) { int element, choice,i; for (i=1; i>0; i++) { cout<< "--------Stack--------\n"; cout<< "1 -> Push \n"; cout<< "2 -> Pop \n"; cout<< "3 -> Top \n"; cout<< "4 -> Empty \n"; cout<< "5 -> Display \n"; cout<< "6 -> Exit \n"; cout<< "7 -> Enter your choice \n"; cin>>choice; switch (choice) { case 1: if (top ==5) { cout<<"\a Error: Overflow\n\n"; } else { cout<<"\a Enter the value\n\n"; cin>>element; push(element); } break; case 2: if (top==-1){ cout<<"\a Stack empty \n"; } else{ cout< case 3: if (top==-1) cout<<"\a stack is empty \n "; else cout< case 4: if (top==-1) cout<<"\a Stack is empty \n "; else cout<<" Stack is not empty \n "; break; case 5: if (top==-1) cout<<"\a Stack is empty\n"; else cout<case 6: exit(0); default: break; } } return 0; } void push(int a){ stack[++top]=a; } int pop(){ return stack[top--]; } string display(){ for (int a=top; a>=0; a--) { cout<<"\n"<< stack[a]<<"\n"; } return "--End--"; }