You are on page 1of 2

#include<iostream>

//#include<conio.h>

int pop();
void push(int);

//stack declaration
struct stack{
int info;
stack *next;
};

stack *temp = NULL,*top = NULL;

using namespace std;

// Function to push element in a dynamic stack


void push(int x){

temp = new stack();


temp->info = x;
temp->next = NULL;

if(top == NULL)
top = temp;
else{

temp->next = top;
top = temp;
}
cout<<" \n The value pushed into stack is "<<top->info;
}

//Function to delete the element from a queue.


int pop (){

int y;

if(top == NULL){

cout<<"stack underflow.";
return 0 ;
}
y = top->info;
temp = top;
top = top->next;
delete temp;

return y;
}
void topvalue(){
cout<<"\n The value at the top of the stack is "<< top->info;
}

/*Main program to be executed*/

int main(){
//clrscr();

push(10);
push(20);
cout<< "\nPoped value is "<<pop();
topvalue();
push(30);
push(40);
cout<< "\nPoped value is "<<pop();
topvalue();
push(50);
push(60);
cout<< "\nPoped value is "<<pop();
topvalue();
//getch();
return 0;

You might also like