Untitled

mail@pastecode.io avatar
unknown
csharp
2 years ago
1.2 kB
1
Indexable
Never
#include <iostream>
#include <stack>
#define max 5
using namespace std;
 stack<int> s;
 int i;
int arr[max];
int item;
int ch;
int top=-1;
int stackCount=0;


void PrintStack(stack<int> s)
{ 
   
    if (s.empty())
        return;
    int x = s.top();
 
    
    s.pop();
    PrintStack(s);
 
    cout <<"\n"<< x << " ";
 
    s.push(x);
}
 
void push(int item){

        s.push(item);
	
}
int pop(int stack[]){

	if(top==1)
	cout<<"-->stack is Empty<--"<<endl;
	else
	{
	
		cout<<"popped item is= " <<s.top()<<endl;
	}
	return s.top();
}
  
// Driver code
int main()
{
    // Stack s
    
 
   	do{
		cout <<"\n"<<"program menu\n";
		cout <<"1. push\n";
		cout <<"2. pop\n";
		cout <<"3. display\n";
		cout <<"4. exit\n";
		cout <<"enter your choice : ";
		cin>>ch;
		switch(ch){
			case 1:
				cout<<"enter an element :";
				 for(int i=0;i<5;i++){
        	
		    	cin>>item;
				push(item);
		    
	         	}
			
			
			break;
			case 2:
			   item=pop(arr);
			     
			break;
			case 3:
				cout <<"elements are : ";
		        PrintStack(s);
			break;
			case 4:
		        	exit(0);
			default:
		      	cout<"Invalid choice";
			break;
		}
	    }
	    while(ch!=4);
	    return 0;
}