Docsity

C++ Stack Implementation, Assignments of History

Partial preview of the text

Download C++ Stack Implementation and more Assignments History in PDF only on Docsity!

#include using namespace std; #define SIZE 5 int A[SIZE]; int top = -1; bool isempty() { if(top==-1) return true; else return false; } void push(int value) { if(top==SIZE-1) { cout<<"Stack is full!\n"; } else { top++; A[top]=value; } } void pop() {

if(isempty()) cout<<"Stack is empty!\n"; else top--; } void show_top() { if(isempty()) cout<<"Stack is empty!\n"; else cout<<"Element at top is: "<<A[top]<<"\n"; } void displayStack() { if(isempty()) { cout<<"Stack is empty!\n"; } else { for(int i=0 ; i<=top; i++) cout<<A[i]<<" "; cout<<"\n"; }