Stack Using Pointer C++
Stack Using Pointer C++
Stack Using Pointer C++
h>
#include<conio.h>
#include<alloc.h>
class stack
public:
struct node
int no;
node *next;
};
node *s,*p;
int m,n;
char yes;
stack()
s->next=NULL;
void select();
void print();
void input();
}o;
node *tmpcell;
p=s;
tmpcell=((node *)(malloc(sizeof(node))));
if(tmpcell==NULL)
cout<<"Out of space.\n";
else
tmpcell->no=x;
tmpcell->next=s->next;
s->next=tmpcell;
m++;
if(!isempty(s))
return s->next->no;
}
cout<<"Empty Stack.\n";
return 0;
node *firstcell;
if(isempty(s))
cout<<"Empty Stack.\n";
else
firstcell=s->next;
s->next=s->next->next;
delete(firstcell);
m--;
return s->next==NULL;
void stack::select()
{
int k,p,e,d,f;
do
cout<<"\n1.Push\t2.Pop\t3.Top\t4.Display\n\n";
cin>>k;
switch(k)
case 1:
if(m==n)
cout<<"Stack is full.\n";
else
cin>>e;
push(e,s);
print();
break;
case 2:
pop(s);
break;
case 3:
top(s);
break;
case 4:
print();
break;
cin>>yes;
while(yes=='y');
void stack::print()
p=s;
if(p->next==NULL)
else
while(p->next!=NULL)
p=p->next;
cout<<"|"<<p->no<<" |"<<endl;
cout<<"|---|\n";
}
}
void stack::input()
cin>>n;
int main()
clrscr();
o.input();
o.select();
getch();
return 0;