Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int top = -1,s = 10;
- void push(int *Stk,int n){
- if(top>=s-1)
- {
- cout<<"Stack Overflow"<<endl;
- }
- else
- {
- top++;
- Stk[top]=n;
- }
- }
- void pop(int *Stk){
- if(top<=-1)
- {
- cout<<"Stack Underflow"<<endl;
- }
- else
- {
- cout<<"The popped element is "<< Stk[top] <<endl;
- top--;
- }
- }
- void display(int *Stk){
- if(top>=0)
- {
- cout<<"Stack elements are: ";
- for(int i=0; i<=top; i++)
- {
- cout<<Stk[i]<<" ";
- }
- cout<<endl;
- }
- else
- {
- cout<<"Stack is empty";
- }
- }
- int main(){
- int *Stack;
- Stack = new int[s];
- push(Stack,5);
- push(Stack,10);
- push(Stack,50);
- push(Stack,56);
- pop(Stack);
- display(Stack);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment