SlideShare uma empresa Scribd logo
1 de 3
#include <iostream>
#include <conio>
class node
{
public:
int info;
node* next;
node(int val,node* ptr=0)
{
info=val;
next=ptr;
}
};
class stack
{
node* top;
public:
stack()
{
top=0;
}
bool isOverflow();
bool isUnderflow();
void push(int val);
void pop();
void display();
};
bool stack::isUnderflow()
{
return (top==0);
}
void stack::push(int val)
{
if(top==0)
{
top=new node(val);
cout<<"Element successfully pushed";
}
else
{
top=new node(val,top);
cout<<"Element successfully pushed";
}
}
void stack::pop()
{
if(isUnderflow())
cout<<"Stack Underflow...Nothing can be popped";
else if(top==0)
{
cout<<"Element popped is:"<<top->info;
delete top;
top=0;
}
else
{
cout<<"Element popped is:"<<top->info;
node* temp=top;
top=top->next;
delete temp;
}
}
void stack::display()
{
if(isUnderflow())
cout<<"Stack Empty...";
else
{
node* temp=top;
cout<<"Stack is as follows"<<endl;
while(temp!=0)
{
cout<<temp->info<<endl;
temp=temp->next;
}
}
}
void main()
{
int choice,v;
char ch;
stack obj;
do
{
cout<<"n ******** Welcome to Stack Menu ********";
cout<<"n ---------------------------------------";
cout<<"n Enter your choice:";
cout<<"nt1.Push";
cout<<"nt2.Pop";
cout<<"nt3.Display"<<endl;
cin>>choice;
switch(choice)
{
case 1:
{
cout<<"Enter the element to be added"<<endl;
cin>>v;
obj.push(v);
break;
}
case 2:obj.pop();
break;
case 3:obj.display();
break;
default:cout<<"nWrong choice";
}
cout<<"nnDo you want to continue? (Y/N)"<<endl;
cin>>ch;
}while(ch=='Y'||ch=='y');
getch();
}

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

Circular queue
Circular queueCircular queue
Circular queue
 
1346
13461346
1346
 
Laziness in Swift
Laziness in Swift Laziness in Swift
Laziness in Swift
 
Document
DocumentDocument
Document
 
Mozilla とブラウザゲーム
Mozilla とブラウザゲームMozilla とブラウザゲーム
Mozilla とブラウザゲーム
 
Pablo Magaz | ECMAScript 2018 y más allá | Codemotion Madrid 2018
Pablo Magaz | ECMAScript 2018 y más allá | Codemotion Madrid 2018Pablo Magaz | ECMAScript 2018 y más allá | Codemotion Madrid 2018
Pablo Magaz | ECMAScript 2018 y más allá | Codemotion Madrid 2018
 
Why scala?
Why scala?Why scala?
Why scala?
 
Burrowing through go! the book
Burrowing through go! the bookBurrowing through go! the book
Burrowing through go! the book
 
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 
contoh Program queue
contoh Program queuecontoh Program queue
contoh Program queue
 
Kotlin killed Java stars
Kotlin killed Java starsKotlin killed Java stars
Kotlin killed Java stars
 
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 
Jarmo van de Seijp Shadbox ERC223
Jarmo van de Seijp Shadbox ERC223Jarmo van de Seijp Shadbox ERC223
Jarmo van de Seijp Shadbox ERC223
 
Finch + Finagle OAuth2
Finch + Finagle OAuth2Finch + Finagle OAuth2
Finch + Finagle OAuth2
 
Final ds record
Final ds recordFinal ds record
Final ds record
 
C program to implement linked list using array abstract data type
C program to implement linked list using array abstract data typeC program to implement linked list using array abstract data type
C program to implement linked list using array abstract data type
 
Pivorak Clojure by Dmytro Bignyak
Pivorak Clojure by Dmytro BignyakPivorak Clojure by Dmytro Bignyak
Pivorak Clojure by Dmytro Bignyak
 
Freeing Tower Bridge
Freeing Tower BridgeFreeing Tower Bridge
Freeing Tower Bridge
 
Blocks+gcd入門
Blocks+gcd入門Blocks+gcd入門
Blocks+gcd入門
 
week-21x
week-21xweek-21x
week-21x
 

Destaque

O que aprendi hoje...
O que aprendi hoje...O que aprendi hoje...
O que aprendi hoje...
letlua22
 
Bagagem da vida
Bagagem da vidaBagagem da vida
Bagagem da vida
isaiasdsh
 
Ana paula e lucas yuri a.b-tadeu
Ana paula e lucas yuri a.b-tadeuAna paula e lucas yuri a.b-tadeu
Ana paula e lucas yuri a.b-tadeu
sorayaday
 
Os 4 evangelhos – joao
Os 4 evangelhos – joaoOs 4 evangelhos – joao
Os 4 evangelhos – joao
igreja-crista
 
Pagina como investir
Pagina   como investir Pagina   como investir
Pagina como investir
Tonivieira
 
Convivencia para el amor y la paz
Convivencia para el amor y  la pazConvivencia para el amor y  la paz
Convivencia para el amor y la paz
Roberto Pérez
 
Aguarde, carregando Balaio Cultural
Aguarde, carregando Balaio CulturalAguarde, carregando Balaio Cultural
Aguarde, carregando Balaio Cultural
culturaourinhos
 

Destaque (20)

O que aprendi hoje...
O que aprendi hoje...O que aprendi hoje...
O que aprendi hoje...
 
Bagagem da vida
Bagagem da vidaBagagem da vida
Bagagem da vida
 
Gps tracker tk 102 apresentação
Gps tracker tk 102 apresentaçãoGps tracker tk 102 apresentação
Gps tracker tk 102 apresentação
 
Ana paula e lucas yuri a.b-tadeu
Ana paula e lucas yuri a.b-tadeuAna paula e lucas yuri a.b-tadeu
Ana paula e lucas yuri a.b-tadeu
 
ENEM OTO Simulado de ciências humanas
ENEM OTO Simulado de ciências humanasENEM OTO Simulado de ciências humanas
ENEM OTO Simulado de ciências humanas
 
Os 4 evangelhos – joao
Os 4 evangelhos – joaoOs 4 evangelhos – joao
Os 4 evangelhos – joao
 
Poluiçao
PoluiçaoPoluiçao
Poluiçao
 
Olhao
OlhaoOlhao
Olhao
 
Diversos
DiversosDiversos
Diversos
 
Libro arte, arqueologia e historia
Libro arte, arqueologia e historia Libro arte, arqueologia e historia
Libro arte, arqueologia e historia
 
Jornal Terra&Campo rumo aos 10 anos
Jornal Terra&Campo rumo aos 10 anosJornal Terra&Campo rumo aos 10 anos
Jornal Terra&Campo rumo aos 10 anos
 
Pagina como investir
Pagina   como investir Pagina   como investir
Pagina como investir
 
Educação conservadora em foco
Educação conservadora em focoEducação conservadora em foco
Educação conservadora em foco
 
Convivencia para el amor y la paz
Convivencia para el amor y  la pazConvivencia para el amor y  la paz
Convivencia para el amor y la paz
 
X! midia mobile
X! midia mobile X! midia mobile
X! midia mobile
 
Scrum em imagens
Scrum em imagensScrum em imagens
Scrum em imagens
 
Um sacrifício que valeu a pena
Um sacrifício que valeu a penaUm sacrifício que valeu a pena
Um sacrifício que valeu a pena
 
Aguarde, carregando Balaio Cultural
Aguarde, carregando Balaio CulturalAguarde, carregando Balaio Cultural
Aguarde, carregando Balaio Cultural
 
Divulgação de resultados 4T11
Divulgação de resultados 4T11Divulgação de resultados 4T11
Divulgação de resultados 4T11
 
Liderança pauta sugerida
Liderança pauta sugeridaLiderança pauta sugerida
Liderança pauta sugerida
 

Semelhante a CODE Data Structures

Datastructures asignment
Datastructures asignmentDatastructures asignment
Datastructures asignment
sreekanth3dce
 
Double linked list header file below for FYI#include iostream.pdf
Double linked list header file below for FYI#include iostream.pdfDouble linked list header file below for FYI#include iostream.pdf
Double linked list header file below for FYI#include iostream.pdf
facevenky
 
double linked list header file code#include iostream#include.pdf
double linked list header file code#include iostream#include.pdfdouble linked list header file code#include iostream#include.pdf
double linked list header file code#include iostream#include.pdf
facevenky
 
Please refer this solution. This is working file for IntegersHeade.pdf
Please refer this solution. This is working file for IntegersHeade.pdfPlease refer this solution. This is working file for IntegersHeade.pdf
Please refer this solution. This is working file for IntegersHeade.pdf
sooryasalini
 
Can you please debug this Thank you in advance! This program is sup.pdf
Can you please debug this Thank you in advance! This program is sup.pdfCan you please debug this Thank you in advance! This program is sup.pdf
Can you please debug this Thank you in advance! This program is sup.pdf
FashionBoutiquedelhi
 
double Skiplist code below#include iostream#include vector.pdf
double Skiplist code below#include iostream#include vector.pdfdouble Skiplist code below#include iostream#include vector.pdf
double Skiplist code below#include iostream#include vector.pdf
txkev
 
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdfHere is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
arrowmobile
 
LinkedListOperations.java-class Node{    public int item;  .pdf
LinkedListOperations.java-class Node{    public int item;  .pdfLinkedListOperations.java-class Node{    public int item;  .pdf
LinkedListOperations.java-class Node{    public int item;  .pdf
aquastore223
 
#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdf#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdf
harihelectronicspune
 
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdfHelp please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
arorastores
 

Semelhante a CODE Data Structures (20)

Datastructures asignment
Datastructures asignmentDatastructures asignment
Datastructures asignment
 
Double linked list header file below for FYI#include iostream.pdf
Double linked list header file below for FYI#include iostream.pdfDouble linked list header file below for FYI#include iostream.pdf
Double linked list header file below for FYI#include iostream.pdf
 
#includeiostream#includecctypeusing namespace std;cl.docx
#includeiostream#includecctypeusing namespace std;cl.docx#includeiostream#includecctypeusing namespace std;cl.docx
#includeiostream#includecctypeusing namespace std;cl.docx
 
Stack and queue
Stack and queueStack and queue
Stack and queue
 
Linked Stack program.docx
Linked Stack program.docxLinked Stack program.docx
Linked Stack program.docx
 
Stack array
Stack arrayStack array
Stack array
 
double linked list header file code#include iostream#include.pdf
double linked list header file code#include iostream#include.pdfdouble linked list header file code#include iostream#include.pdf
double linked list header file code#include iostream#include.pdf
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Please refer this solution. This is working file for IntegersHeade.pdf
Please refer this solution. This is working file for IntegersHeade.pdfPlease refer this solution. This is working file for IntegersHeade.pdf
Please refer this solution. This is working file for IntegersHeade.pdf
 
Can you please debug this Thank you in advance! This program is sup.pdf
Can you please debug this Thank you in advance! This program is sup.pdfCan you please debug this Thank you in advance! This program is sup.pdf
Can you please debug this Thank you in advance! This program is sup.pdf
 
double Skiplist code below#include iostream#include vector.pdf
double Skiplist code below#include iostream#include vector.pdfdouble Skiplist code below#include iostream#include vector.pdf
double Skiplist code below#include iostream#include vector.pdf
 
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdfHere is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
 
week-17x
week-17xweek-17x
week-17x
 
week-18x
week-18xweek-18x
week-18x
 
LinkedListOperations.java-class Node{    public int item;  .pdf
LinkedListOperations.java-class Node{    public int item;  .pdfLinkedListOperations.java-class Node{    public int item;  .pdf
LinkedListOperations.java-class Node{    public int item;  .pdf
 
Please review my code (java)Someone helped me with it but i cannot.pdf
Please review my code (java)Someone helped me with it but i cannot.pdfPlease review my code (java)Someone helped me with it but i cannot.pdf
Please review my code (java)Someone helped me with it but i cannot.pdf
 
CBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical fileCBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical file
 
Ds 2 cycle
Ds 2 cycleDs 2 cycle
Ds 2 cycle
 
#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdf#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdf
 
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdfHelp please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
 

Mais de Sonia Pahuja (14)

numerical method solutions
numerical method solutionsnumerical method solutions
numerical method solutions
 
Bisection method solved questions
Bisection method solved questionsBisection method solved questions
Bisection method solved questions
 
raster and random scan
raster and random scanraster and random scan
raster and random scan
 
Scanfill polygon
Scanfill polygonScanfill polygon
Scanfill polygon
 
Graphics exercise (b.tech)
Graphics exercise (b.tech)Graphics exercise (b.tech)
Graphics exercise (b.tech)
 
graphics notes
graphics notesgraphics notes
graphics notes
 
Graphics exercise (b.tech)
Graphics exercise (b.tech)Graphics exercise (b.tech)
Graphics exercise (b.tech)
 
Surajkund Mella Faridabad
Surajkund Mella FaridabadSurajkund Mella Faridabad
Surajkund Mella Faridabad
 
Business Ethics
Business Ethics Business Ethics
Business Ethics
 
Determinant Matlab Code
Determinant Matlab CodeDeterminant Matlab Code
Determinant Matlab Code
 
Gaussel Method
Gaussel MethodGaussel Method
Gaussel Method
 
DATABASE MANAGEMENT SYSTEM
DATABASE MANAGEMENT SYSTEMDATABASE MANAGEMENT SYSTEM
DATABASE MANAGEMENT SYSTEM
 
Introduction to sets
Introduction to setsIntroduction to sets
Introduction to sets
 
Data Link Control
Data Link ControlData Link Control
Data Link Control
 

Último

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
dollysharma2066
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Christo Ananth
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
MsecMca
 

Último (20)

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 

CODE Data Structures

  • 1. #include <iostream> #include <conio> class node { public: int info; node* next; node(int val,node* ptr=0) { info=val; next=ptr; } }; class stack { node* top; public: stack() { top=0; } bool isOverflow(); bool isUnderflow(); void push(int val); void pop(); void display(); }; bool stack::isUnderflow() { return (top==0); } void stack::push(int val) { if(top==0) { top=new node(val); cout<<"Element successfully pushed"; } else { top=new node(val,top); cout<<"Element successfully pushed"; } } void stack::pop() { if(isUnderflow()) cout<<"Stack Underflow...Nothing can be popped"; else if(top==0) { cout<<"Element popped is:"<<top->info; delete top; top=0; }
  • 2. else { cout<<"Element popped is:"<<top->info; node* temp=top; top=top->next; delete temp; } } void stack::display() { if(isUnderflow()) cout<<"Stack Empty..."; else { node* temp=top; cout<<"Stack is as follows"<<endl; while(temp!=0) { cout<<temp->info<<endl; temp=temp->next; } } } void main() { int choice,v; char ch; stack obj; do { cout<<"n ******** Welcome to Stack Menu ********"; cout<<"n ---------------------------------------"; cout<<"n Enter your choice:"; cout<<"nt1.Push"; cout<<"nt2.Pop"; cout<<"nt3.Display"<<endl; cin>>choice; switch(choice) { case 1: { cout<<"Enter the element to be added"<<endl; cin>>v; obj.push(v); break; } case 2:obj.pop(); break; case 3:obj.display(); break; default:cout<<"nWrong choice"; } cout<<"nnDo you want to continue? (Y/N)"<<endl; cin>>ch;