Just the if function executes in the functions and does'nt go to the next condition below the if condition.
What could have possibly gone wrong?
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
struct stack
{
int info;
stack *next;
};
stack *top=NULL;
void push()
{
int data;
cout<<"Enter data";
cin>>data;
//create a new node
stack*ptr=new stack;
ptr->info=data;
ptr->next=top;
}
void pop()
{
stack *ptr;
//empty
if(top==NULL)
{
cout<<"Stack empty";
return;
}
ptr=top;
cout<<ptr->info;
top=ptr->next;
delete ptr;
}
void display()
{
if(top==NULL)
{
cout<<"Stack empty";
return;
}
stack *ptr=top;
while(ptr!=NULL)
{
cout<<ptr->info;
ptr=ptr->next;
}
}
void main()
{
int op;
char cnt;
do
{
cout<<"1.Insert";
cout<<"2.Deletion";
cout<<"3.Display";
cout<<"4.Exit";
cout<<"Enter the choice";
cin>>op;
switch(op)
{
case 1:push();
break;
case 2:pop();
break;
case 3:display();
break;
case 4: exit(0);
}
cout<<"Do you wanna continue ?";
cin>>cnt;
}
while(cnt=='Y'||cnt=='y');
}