STK Linklist
STK Linklist
Roll no.: 80
Practical no:
Title: Implementation of Linked list using Stack.
#include<iostream.h>
#include<conio.h>
class NODE
{
public:
int data;
NODE*link;
};
class STACK
{
NODE*start;
public:
STACK();
void PUSH_80(int);
int POP_80();
int PEEP_80();
void VIEWALL_80();
};
STACK::STACK()
{
start=NULL;
}
void STACK::PUSH_80(int ele)
{
NODE *NN = new NODE(); //step_1 Create new node
NN -> data = ele; //step_2 fill data
NN -> link = NULL;
//set links
if(start==NULL)
start=NN;
else
{
NN->link=start;
start=NN;
}
}
Int STACK:: POP_80()
{
if(start==NULL)
{
cout<<endl<<"List is Empty";
return NULL;
}
else
{
int ele;
ele=start->data;
start=start->link;
return ele;
}
}
int STACK::PEEP_80()
{
if(start==NULL)
{
cout<<endl<<"List is empty";
return NULL;
}
else
{
return start->data;
}
}
void STACK::VIEWALL_80()
{
if(start==NULL)
cout<<endl<<"List is empty";
else
{
NODE *temp_ptr=start;
while(temp_ptr != NULL)
{
cout<<" "<<temp_ptr->data;
temp_ptr=temp_ptr->link;
}
}
}
void MENU()
{
int ch,ele;
STACK s;
do
{
cout<<"\n Select any option";
cout<<"\n 1.PUSH_80";
cout<<"\n 2.POP_80";
cout<<"\n 3.PEEP_80";
cout<<"\n 4.VIEWALL_80";
cout<<"\n 5.EXIT";
cout<<"\n Enter your choice: ";
cin>>ch;
switch(ch)
{
case1 : cout<<endl<<" Enter the element: ";
cin>>ele;
s.PUSH_80(ele);
break;
case2 : cout<<endl<<s.POP_80()<<" is Deleted.";
break;
case3 : cout<<endl<<s.PEEP_80()<<"is the Topmost element";
break;
case4 : cout<<endl<<"The list elements are ";
s.VIEWALL_80()
break;
case5 :return;
void main()
{
clrscr();
MENU();
getch();
}