SlideShare a Scribd company logo
2
Most read
7
Most read
8
Most read
STACKS INC++
INTRODUCTION TO
STACK
DEFINITION:
 A stack is a data structure that provides temporary storage of data
in such
a way that theelement stored last will be retrieved first.
 This method is also called LIFO – Last In First Out.
EXAMPLE:
In real life we can think of stack as a stack of copies, stack of plates
etc. The first copy put in the stack is the last one to be removed.
Similarly last copy to put in the stack is the first one to be removed.
OPERATIONS ON
STACK
 A stack is a linear data structure.
 It is controlled by two operations: push and pop.
 Both the operations take place from one end of the stack,
usually called top. Top points to the current top position of
the stack.
 Push operation adds an element to the top of the stack.
 Pop operation removes an element from the top of the
stack.
 These two operations implements the LIFO method .
IMPLEMENTATION OF
STACK
Stack can be implemented in two
ways:
 As an Array
 As a Linked List
STACK AS AN
ARRAY
Array implementation of stack
uses
 an array to store data
 an integer type variable usually called the top,
which points to the top of the stack.
NOTE: The variable top contains the index
number of the top most filled element of the
array.
30
20
10
2
4
3
2
1
0
TOP
PUSH
OPERATION
 Initially when the stack is empty, TOP can have any
integer value other than any valid index number of the
array. Let TOP =
-1;
 The first element in the empty stack goes to the 0th
position of the array and the Top is initialized to value 0.
 After this every push operation increase the TOP by
1 and inserts new data at that particular position.
 As arrays are fixed in length, elements can not be
inserted beyond the maximum size of the array.
Pushing data beyond the maximum size of the stack
results in “data overflow”.
PUSHOPERATION EXPLAINED
NOTE:Pushing one more element into the stack will result in overflow.
POP OPERATION
The pop operation deletes the most recently entered item from
the stack.
Any attempt to delete an element from the empty stack results
in “data underflow” condition.
The variableTOPcontains the index number of the current top
position ofthe stack.
Eachtime the pop operation is performed, theTOPvariable is
decremented by1.
POPOPERATION EXPLAINED
top =2
APPLICATIONS OF STACK
Astack is anappropriate data structure on which information is stored and
then later retrieved in reverse order.The application of stack areasfollows:
When a program executes, stack is used to store the return address at time
of function call. After the execution of the function is over, return address is
popped from stackand control is returned back to the calling function.
Converting an infix expression o postfix operation and to evaluate the
postfix expression.
Reversingan array, converting decimal number into binary number etc.
INFIX AND POSTFIX OPERATIONS
 The infix expression is aconventional algebraic expression, in
which the operator is in between the operands.
For example:a+b
 In the postfix expression the operator is placed after the
operands.
For example:ab+
NEED OF POSTFIX EXPRESSION
The postfixexpressions are special because
 They do notuseparenthesis
 The order of expression is uniquely reconstructed from the
expression itself.
Theseexpressions are useful in computer applications.
CONVERTING INFIX TO POSTFIX EXPRESSION
CONVERT_I_P(I,P
,STACK) Where I =infix expression, P=postfix expression,STACK=stack asan array
Step1.Push‘(‘ into STACKandadd‘)’to the endof I.
Step2.ScanexpressionIfrom left to right andrepeatsteps3-6for eachelement of I untilthe stack is
empty.
Step3.If scannedelement =‘(‘, pushit into the STACK. Step4.If
scannedelement =operand,addit to P
.
Step5.If scannedelement =operator,then:
a)Repeatedly pop from STACKand add to Peachoperator from the top of the stackuntil
the operatorat the top of the stackhaslower precedencethan the operatorextracted from I.
b) Addscannedoperatorto the top of theSTACK. Step6.If
scannedelement =‘)’then:
c)RepeatedlypopfromSTACKandaddto Peachoperatoruntil the left parenthesis is
encountered.
d) Popthe left parenthesisbut do not addto P
.
CONVERTING INFIXTO POSTFIX EXPRESSION
QConvert the following infix operation to
postfix operation.
((TRUE&& FALSE)|| ! (FALSE|| TRUE))
Ans.The Postfix expression is:
TRUE FALSE&& FALSETRUE|| ! ||
EVALUATION OF POSTFIX EXPRESSION
Evaluate(P, result, STACK)
where P=Postfix expression,STACK=stack,result=to hold the result of evaluation
Step 1.Scanthe postfix expression Pfrom left to right and repeat the steps 2, 3
until theSTACKis empty.
Step 2. If the scanned element =operand,pushit into the STACK.
Step 3. If the scanned element =operator,then
a) Popthe two operands viz operandAand operand Bfrom the STACK.
b) Evaluate ((operand B)operator (operandA))
c) Pushthe result of evaluation into the STACK.
Step 4.Set result=top most element of the STACK.
EVALUATING POSTFIXEXPRESSION
Q Evaluate the following Postfixexpression:
TRUE FALSE || FALSE TRUE&& ! ||
Ans. TRUE Ste
p
No.
SymbolScanned Operation Performed Stack Status
1 TRUE TRUE
2 FALSE TRUEFALSE
3 || TRUE || FALSE =TRUE TRUE
4 FALSE TRUEFALSE
5 TRUE TRUEFALSE TRUE
6 && FALSE&& TRUE=FALSE TRUEFALSE
7 ! ! FALSE= TRUE TRUE TRUE
8 || TRUE || TRUE TRUE
STACK AS A LINKED LIST
Linked list implementation of stack uses
 Alinked list to store data
 ApointerTOPpointing to the top most position of the stack.
NOTE:Eachnode of astack asalinked list hastwo parts : data part and link part and
is created with the help of self referential structure.
Thedata part stores the data and link part stores the addressof the next node of the
linked list.
NODE
TOP
DATA LINK
PROGRAM TO ILLUSTRATE OPERATIONS ON STACK
ASA LINKED LIST
#include<iostream.h>
#include<conio.h>
struct node
{
int roll;
charname[20];
float total;
node *next;
};
classstack
{
node *top;
public :
stack()
{ top=NULL;}
void push();
void pop();
void display();
};
void stack::push()
{
node *temp;
temp=new node;
cout<<"Enter roll :";
cin>>temp->roll;
cout<<"Enter name:";
cin>>temp->name;
cout<<"Enter total :";
cin>>temp->total;
temp->next=top;
top=temp;
}
void stack::pop()
{
if(top!=NULL)
{
node*temp=top;
top=top->next;
cout<<temp->roll<<temp-
>name<<temp->total
<<"deleted";
delete temp;
}
else
cout<<"Stack empty";
}
void stack::display()
{
node *temp=top;
while(temp!=NULL)
{
cout<<temp->roll<<temp-
>name<<temp->total<<" ";
temp=temp->next;
} }
void main()
{ stack st;
char ch;
do
{ cout<<"stack
optionsnPpush
nO PopnD
Display nQquit";
cin>>ch;
switch(ch)
{ case'P':
st.push();break;
case'O':
st.pop();break;
case'D':
st.display();break;
}
}while(ch!='Q');
}
PROGRAM TO ILLUSTRATE OPERATIONS ON STACK
AS A LINKED LIST :Explanation
struct node
{
int roll;
charname[20];
float total;
node *next;
};
Self Referential Structure:Theseare specialstructures which
contains pointers tothemselves.
Here, next is apointer of type node itself.
Self Referential structures are needed to create Linked Lists.
classstack
{
node*top;
public :
stack()
{ top=NULL;}
void push();
void pop();
void display();
};
classstack: It contains pointerTOPwhich will point to the top
of thestack.
Theconstructor function initializesTOPto NULL.
PROGRAM TO ILLUSTRATE OPERATIONS ON STACK
AS A LINKED LIST :Explanation
void stack::push()
{
node *temp; // pointer of type node
temp=new node; // new operator will create a new
//node and address of new node
// is stored in temp
cout<<"Enter roll:";
Theselines will input
values into roll , name
and total of newly
created node.
cin>>temp->roll;
cout<<"Enter name:";
cin>>temp->name;
cout<<"Enter total:";
cin>>temp->total;
temp->next=top; // address stored in TOPgets
//stored in next of newly
//created node.
top=temp; // Topwill contain address of
// newly created node
}
void stack::pop()
{
if(top!=NULL) // if stack is not empty
{
node *temp=top; // temp is a pointer
//containing address of first node
top=top->next; // top will now containaddress of
//second node
cout<<temp->roll<<
temp->name<<temp->total
<<"deleted";
//This line will display
//data stored in
// deleted node
delete temp; // delete operator will delete the node
// stored attemp
}
else
cout<<"Stack empty";}

More Related Content

What's hot (20)

PPT
Stacks overview with its applications
Saqib Saeed
 
PPTX
stacks and queues
EktaVaswani2
 
PPT
data structure, stack, stack data structure
pcnmtutorials
 
PPTX
Data structure Stack
Praveen Vishwakarma
 
PPT
stack and queue array implementation in java.
CIIT Atd.
 
PPSX
Stack
Seema Sharma
 
PDF
STACK ( LIFO STRUCTURE) - Data Structure
Yaksh Jethva
 
PPTX
Stack of Data structure
Sheikh Monirul Hasan
 
PPT
Stack linked list
bhargav0077
 
PDF
04 stacks
Rajan Gautam
 
PPTX
Stacks in c++
Vineeta Garg
 
PPTX
Stack project
Amr Aboelgood
 
PPT
stack presentation
Shivalik college of engineering
 
PPTX
STACKS IN DATASTRUCTURE
Archie Jamwal
 
PPTX
Stack Data Structure
Afaq Mansoor Khan
 
PPTX
Introduction To Stack
Education Front
 
PPTX
Application of Stack - Yadraj Meena
Dipayan Sarkar
 
PPT
Stacks and queue
Amit Vats
 
PPTX
Stack organization
chauhankapil
 
PPTX
Stack Data Structure
Rabin BK
 
Stacks overview with its applications
Saqib Saeed
 
stacks and queues
EktaVaswani2
 
data structure, stack, stack data structure
pcnmtutorials
 
Data structure Stack
Praveen Vishwakarma
 
stack and queue array implementation in java.
CIIT Atd.
 
STACK ( LIFO STRUCTURE) - Data Structure
Yaksh Jethva
 
Stack of Data structure
Sheikh Monirul Hasan
 
Stack linked list
bhargav0077
 
04 stacks
Rajan Gautam
 
Stacks in c++
Vineeta Garg
 
Stack project
Amr Aboelgood
 
STACKS IN DATASTRUCTURE
Archie Jamwal
 
Stack Data Structure
Afaq Mansoor Khan
 
Introduction To Stack
Education Front
 
Application of Stack - Yadraj Meena
Dipayan Sarkar
 
Stacks and queue
Amit Vats
 
Stack organization
chauhankapil
 
Stack Data Structure
Rabin BK
 

Similar to Stack data structure (20)

PPTX
Chapter 5-stack.pptx
Halid Assen
 
PPTX
Introduction to information about Data Structure.pptx
tarrebulehora
 
PPTX
Stacks and queues using aaray line .pptx
ramkumar649780
 
PDF
Data structures stacks
maamir farooq
 
PPT
week 7,8,10,11 alll files included from .ppt
LidetAdmassu
 
PPTX
Unit II - LINEAR DATA STRUCTURES
Usha Mahalingam
 
PPTX
DATA STRUCTURE - STACK
Devyani Chaudhari
 
PPT
Stack ppt file of Stack DSA For lab in the lab of DSA lecture and Lab.ppt
aamirali1061a
 
PPTX
Stacks Data structure.pptx
line24arts
 
PPTX
Stack.pptx
AliRaza899305
 
PPT
Stacks
sweta dargad
 
PDF
Stack
Zaid Shabbir
 
PPTX
STACK AND ITS OPERATIONS IN DATA STRUCTURES.pptx
KALPANAC20
 
PPTX
Data Structure and Algorithms by Sabeen Memon03.pptx
msoomar8611
 
PPT
Concept of stack ,stack of aaray stack by linked list , application of stac...
muskankumari7360
 
PPTX
c programming and data structure notes for ECE
ShaMaa11
 
PPTX
STACK AND QUEUE CIRCULAR QUEUE PPTS.pptx
sunitha1792
 
PPTX
DS-UNIT 3 FINAL.pptx
prakashvs7
 
PPTX
Unit 3 Stacks and Queues.pptx
Yogesh Pawar
 
PPT
Stack data structures with definition and code
bansidharj11
 
Chapter 5-stack.pptx
Halid Assen
 
Introduction to information about Data Structure.pptx
tarrebulehora
 
Stacks and queues using aaray line .pptx
ramkumar649780
 
Data structures stacks
maamir farooq
 
week 7,8,10,11 alll files included from .ppt
LidetAdmassu
 
Unit II - LINEAR DATA STRUCTURES
Usha Mahalingam
 
DATA STRUCTURE - STACK
Devyani Chaudhari
 
Stack ppt file of Stack DSA For lab in the lab of DSA lecture and Lab.ppt
aamirali1061a
 
Stacks Data structure.pptx
line24arts
 
Stack.pptx
AliRaza899305
 
Stacks
sweta dargad
 
STACK AND ITS OPERATIONS IN DATA STRUCTURES.pptx
KALPANAC20
 
Data Structure and Algorithms by Sabeen Memon03.pptx
msoomar8611
 
Concept of stack ,stack of aaray stack by linked list , application of stac...
muskankumari7360
 
c programming and data structure notes for ECE
ShaMaa11
 
STACK AND QUEUE CIRCULAR QUEUE PPTS.pptx
sunitha1792
 
DS-UNIT 3 FINAL.pptx
prakashvs7
 
Unit 3 Stacks and Queues.pptx
Yogesh Pawar
 
Stack data structures with definition and code
bansidharj11
 
Ad

Recently uploaded (20)

PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
Biography of Daniel Podor.pdf
Daniel Podor
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
Biography of Daniel Podor.pdf
Daniel Podor
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Ad

Stack data structure

  • 2. INTRODUCTION TO STACK DEFINITION:  A stack is a data structure that provides temporary storage of data in such a way that theelement stored last will be retrieved first.  This method is also called LIFO – Last In First Out. EXAMPLE: In real life we can think of stack as a stack of copies, stack of plates etc. The first copy put in the stack is the last one to be removed. Similarly last copy to put in the stack is the first one to be removed.
  • 3. OPERATIONS ON STACK  A stack is a linear data structure.  It is controlled by two operations: push and pop.  Both the operations take place from one end of the stack, usually called top. Top points to the current top position of the stack.  Push operation adds an element to the top of the stack.  Pop operation removes an element from the top of the stack.  These two operations implements the LIFO method .
  • 4. IMPLEMENTATION OF STACK Stack can be implemented in two ways:  As an Array  As a Linked List
  • 5. STACK AS AN ARRAY Array implementation of stack uses  an array to store data  an integer type variable usually called the top, which points to the top of the stack. NOTE: The variable top contains the index number of the top most filled element of the array. 30 20 10 2 4 3 2 1 0 TOP
  • 6. PUSH OPERATION  Initially when the stack is empty, TOP can have any integer value other than any valid index number of the array. Let TOP = -1;  The first element in the empty stack goes to the 0th position of the array and the Top is initialized to value 0.  After this every push operation increase the TOP by 1 and inserts new data at that particular position.  As arrays are fixed in length, elements can not be inserted beyond the maximum size of the array. Pushing data beyond the maximum size of the stack results in “data overflow”.
  • 7. PUSHOPERATION EXPLAINED NOTE:Pushing one more element into the stack will result in overflow.
  • 8. POP OPERATION The pop operation deletes the most recently entered item from the stack. Any attempt to delete an element from the empty stack results in “data underflow” condition. The variableTOPcontains the index number of the current top position ofthe stack. Eachtime the pop operation is performed, theTOPvariable is decremented by1.
  • 10. APPLICATIONS OF STACK Astack is anappropriate data structure on which information is stored and then later retrieved in reverse order.The application of stack areasfollows: When a program executes, stack is used to store the return address at time of function call. After the execution of the function is over, return address is popped from stackand control is returned back to the calling function. Converting an infix expression o postfix operation and to evaluate the postfix expression. Reversingan array, converting decimal number into binary number etc.
  • 11. INFIX AND POSTFIX OPERATIONS  The infix expression is aconventional algebraic expression, in which the operator is in between the operands. For example:a+b  In the postfix expression the operator is placed after the operands. For example:ab+
  • 12. NEED OF POSTFIX EXPRESSION The postfixexpressions are special because  They do notuseparenthesis  The order of expression is uniquely reconstructed from the expression itself. Theseexpressions are useful in computer applications.
  • 13. CONVERTING INFIX TO POSTFIX EXPRESSION CONVERT_I_P(I,P ,STACK) Where I =infix expression, P=postfix expression,STACK=stack asan array Step1.Push‘(‘ into STACKandadd‘)’to the endof I. Step2.ScanexpressionIfrom left to right andrepeatsteps3-6for eachelement of I untilthe stack is empty. Step3.If scannedelement =‘(‘, pushit into the STACK. Step4.If scannedelement =operand,addit to P . Step5.If scannedelement =operator,then: a)Repeatedly pop from STACKand add to Peachoperator from the top of the stackuntil the operatorat the top of the stackhaslower precedencethan the operatorextracted from I. b) Addscannedoperatorto the top of theSTACK. Step6.If scannedelement =‘)’then: c)RepeatedlypopfromSTACKandaddto Peachoperatoruntil the left parenthesis is encountered. d) Popthe left parenthesisbut do not addto P .
  • 14. CONVERTING INFIXTO POSTFIX EXPRESSION QConvert the following infix operation to postfix operation. ((TRUE&& FALSE)|| ! (FALSE|| TRUE)) Ans.The Postfix expression is: TRUE FALSE&& FALSETRUE|| ! ||
  • 15. EVALUATION OF POSTFIX EXPRESSION Evaluate(P, result, STACK) where P=Postfix expression,STACK=stack,result=to hold the result of evaluation Step 1.Scanthe postfix expression Pfrom left to right and repeat the steps 2, 3 until theSTACKis empty. Step 2. If the scanned element =operand,pushit into the STACK. Step 3. If the scanned element =operator,then a) Popthe two operands viz operandAand operand Bfrom the STACK. b) Evaluate ((operand B)operator (operandA)) c) Pushthe result of evaluation into the STACK. Step 4.Set result=top most element of the STACK.
  • 16. EVALUATING POSTFIXEXPRESSION Q Evaluate the following Postfixexpression: TRUE FALSE || FALSE TRUE&& ! || Ans. TRUE Ste p No. SymbolScanned Operation Performed Stack Status 1 TRUE TRUE 2 FALSE TRUEFALSE 3 || TRUE || FALSE =TRUE TRUE 4 FALSE TRUEFALSE 5 TRUE TRUEFALSE TRUE 6 && FALSE&& TRUE=FALSE TRUEFALSE 7 ! ! FALSE= TRUE TRUE TRUE 8 || TRUE || TRUE TRUE
  • 17. STACK AS A LINKED LIST Linked list implementation of stack uses  Alinked list to store data  ApointerTOPpointing to the top most position of the stack. NOTE:Eachnode of astack asalinked list hastwo parts : data part and link part and is created with the help of self referential structure. Thedata part stores the data and link part stores the addressof the next node of the linked list. NODE TOP DATA LINK
  • 18. PROGRAM TO ILLUSTRATE OPERATIONS ON STACK ASA LINKED LIST #include<iostream.h> #include<conio.h> struct node { int roll; charname[20]; float total; node *next; }; classstack { node *top; public : stack() { top=NULL;} void push(); void pop(); void display(); }; void stack::push() { node *temp; temp=new node; cout<<"Enter roll :"; cin>>temp->roll; cout<<"Enter name:"; cin>>temp->name; cout<<"Enter total :"; cin>>temp->total; temp->next=top; top=temp; } void stack::pop() { if(top!=NULL) { node*temp=top; top=top->next; cout<<temp->roll<<temp- >name<<temp->total <<"deleted"; delete temp; } else cout<<"Stack empty"; } void stack::display() { node *temp=top; while(temp!=NULL) { cout<<temp->roll<<temp- >name<<temp->total<<" "; temp=temp->next; } } void main() { stack st; char ch; do { cout<<"stack optionsnPpush nO PopnD Display nQquit"; cin>>ch; switch(ch) { case'P': st.push();break; case'O': st.pop();break; case'D': st.display();break; } }while(ch!='Q'); }
  • 19. PROGRAM TO ILLUSTRATE OPERATIONS ON STACK AS A LINKED LIST :Explanation struct node { int roll; charname[20]; float total; node *next; }; Self Referential Structure:Theseare specialstructures which contains pointers tothemselves. Here, next is apointer of type node itself. Self Referential structures are needed to create Linked Lists. classstack { node*top; public : stack() { top=NULL;} void push(); void pop(); void display(); }; classstack: It contains pointerTOPwhich will point to the top of thestack. Theconstructor function initializesTOPto NULL.
  • 20. PROGRAM TO ILLUSTRATE OPERATIONS ON STACK AS A LINKED LIST :Explanation void stack::push() { node *temp; // pointer of type node temp=new node; // new operator will create a new //node and address of new node // is stored in temp cout<<"Enter roll:"; Theselines will input values into roll , name and total of newly created node. cin>>temp->roll; cout<<"Enter name:"; cin>>temp->name; cout<<"Enter total:"; cin>>temp->total; temp->next=top; // address stored in TOPgets //stored in next of newly //created node. top=temp; // Topwill contain address of // newly created node } void stack::pop() { if(top!=NULL) // if stack is not empty { node *temp=top; // temp is a pointer //containing address of first node top=top->next; // top will now containaddress of //second node cout<<temp->roll<< temp->name<<temp->total <<"deleted"; //This line will display //data stored in // deleted node delete temp; // delete operator will delete the node // stored attemp } else cout<<"Stack empty";}