Write a program to create a …
CBSE, JEE, NEET, CUET
Question Bank, Mock Tests, Exam Papers
NCERT Solutions, Sample Papers, Notes, Videos
Posted by Saurav Anand 7 years, 9 months ago
- 1 answers
Related Questions
Posted by Syedali Fathima 5 months, 4 weeks ago
- 1 answers
Posted by Prawar Narang 6 months, 2 weeks ago
- 1 answers
Posted by Hanni Pham 4 months, 2 weeks ago
- 0 answers
Posted by Manoj Kumar Manoj Kumar 7 months, 2 weeks ago
- 0 answers
Posted by Kandeepan Jothivel 6 months, 4 weeks ago
- 2 answers
Posted by Priya Shukla 5 months, 3 weeks ago
- 1 answers
Posted by Hanni Pham 4 months, 2 weeks ago
- 1 answers
myCBSEguide
Trusted by 1 Crore+ Students
Test Generator
Create papers online. It's FREE.
CUET Mock Tests
75,000+ questions to practice only on myCBSEguide app
Deepa Sanil 7 years, 4 months ago
#include <iostream.h>
#include<conio.h>
#include<process.h>
struct node
{ int info;
node *next;
};
node *top,*newptr,*temp,*ptr;
node *createnode(int);
void push(node*);
void display(node*);
void pop();
void main()
{clrscr();
top=NULL;
int ch,info;
char ch1,ch2;
do {
clrscr();
cout<<"\n \n1. Push \n2. Pop\n3. Display \n4. Exit\n";
cout<<"\nEnter your choice : ";
cin>>ch;
switch(ch)
{
case 1:
cout<<"Enter the item : ";
cin>>info;
newptr=createnode(info);
push(newptr);
break;
case 2:
cout<<"Do u want to delete the first node?";
cin>>ch1;
if(ch1=='y'||ch1=='Y')
pop();
cout<<"Now the list is:\n";
display(top);
break;
case 3:
display(top);
break;
case 4:
exit(0);
default:
cout<<"Invalid choice. Please try again. \n";
} cout<<"\n\nDo u want to continue";
cin>>ch2;
} while(ch2=='y');
getch();
}
node* createnode(int n)
{
ptr=new node;
ptr->info=n;
ptr->next=NULL;
return ptr;
}
void push(node* np)
{
if(top==NULL)
top=np;
else
{
temp=top;
top=np;
np->next=temp;
}
cout<<"\nItem inserted:"<<np->info;
}
void pop()
{
if(top==NULL)
cout<<"Underflow!!\n";
else
{
ptr=top;
top=top->next;
delete ptr;
}
}
void display(node* np)
{
while(np!=NULL)
{
cout<<np->info<<"-->";
np=np->next;
}
cout<<"\n";
}
0Thank You