Computer Science, asked by roshu2002, 1 year ago

perform following Operation on stack of size 5. push(30). push(12). push(10). pop(). push(45). pop(70)

Answers

Answered by nitish8089
7
// output: 70 45 12 30

#include <iostream>

using namespace std;

template<class T>

 class stack{

int top;

public:

T a[5];

stack(){

 top=-1;

}

void push(T x);

T pop();

void isEmpty();

void display();

};

template<class T>

void stack<T>::push(T x){

if(top>=5){

 cout<<"stack is overflow \n";

}

else{

 a[++top]=x;

 cout<<"Element Inserted "<<x<<"\n";

}

}

template<class T>

T stack<T>::pop(){

if(top<0){

 cout<<"stack underflow \n";

}

else{

 T d=a[top--];

 return d;

}

}

template<class T>

void stack<T>::isEmpty(){

if(top<0){

 cout<<"stack is empty \n";

}

else{

 cout<<"Stack is not empty";

}

}

template<typename T>

void stack<T>::display(){

if(top<0){

 cout<<"Stack is xempty";

}

else{

 for(int x=top;x>=0;x--){

  cout<<"stack content\n";

  cout<<a[x]<<endl;

 }

}

}

int main(){

// integer type stack built

stack<int> s1;

s1.push(30);

       s1.push(12);

       s1.push(10);

       s1.pop();

       s1.push(45);

       s1.pop(70);

       s1.display();

}

nitish8089: pop 10 hua hai...
roshu2002: turbo c pe kiya run ...
nitish8089: are waha run nahi hoga...
roshu2002: but uspe to hote hai na c++ ke program
roshu2002: he
nitish8089: i know but c++ ke syntax turbo me thoda sa alag hota hai...
roshu2002: please aap muze program run kr ke pics send karoge kya...becoz mera program run hi nai ho rha hai
nitish8089: i posted the screenshot in your one of answer may help ypu..
roshu2002: sorry mai aapko bahut pareshan kar rahi hu.... please muze ye program c mai batao
roshu2002: SORRY...
Similar questions