SlideShare a Scribd company logo
1 of 7
Download to read offline
Stack
Stack is a linear list where any element is added at the top of the list and any element is deleted
(accessed) from the top of the list. So, for stack an indicator or pointer must be used to indicate or
point the top element of the stack.
Add operation for a stack is called “push” operation and deletion operation is called “pop”
operation. Stack is a LIFO (Last In First Out) structure. That means the element which was added
last will be deleted or accessed first.
The elements of a stack are added from bottom to top, means push operation is performed from
bottom to top. The elements are deleted from top to bottom, which means pop operation is
performed from top to bottom.
Stack can be implemented using two ways; using array and using linked list.
8
7
6
5 1923
4 1452
3 2315
2 1245
1 1025
(a) Array based stack
40 48 59 67 63
(b) A link based stack
Fig. 1: Graphical representation of stack
Array Based Stack
The stack, which is implemented using array is called array based stack. To create an array based
stack, at first we have to declare an array with required size.
Push Operation
Push operation means to add an element to a stack.
Here, we shall use array based stack. So, an array will be treated as a stack. We need an indicator
or index identifier to add element to the stack and this indicator will mark the top of the stack. To
add an element we have to check whether the array is already full or not. If the array is already full
then we cannot add any element, otherwise we can.
Here, top is an indicator indicates the top element of the stack and item is an element to be added
to the stack, M is the size of the stack (array). Overflow occurs when we try to insert an element
into the stack, which is already full.
top
(top=5
)
6
5
4 D
3 Q
2 F
1 A
(a) Before push
(b) After push
Fig. 2: Pictorial view of push operation
Algorithm to add an element to a stack
1. Declare the stack and top:
stack[[1…..M], top;
2, Add an item in the stack:
if(top<M)
{
top=top+1;
stack[top]=item;
}
else print “Over Flow”;
3. Output will be the updated stack.
Pop Operation
Pop operation means to delete (access) an element from a stack. Here, top is an indicator indicates
the top element of the stack, M is the size of the array and x is a variable where we access top
element of the stack.
6
5
4 D
3 Q
2 F
1 A
(a) Before pop (b) After pop
Fig. 3: Pictorial view of pop operation
6
5 H
4 D
3 Q
2 F
1 A
6
5 H
4 D
3 Q
2 F
1 A
top
(top=4
)
top
(top=5
)
top
(top=5
)
top
(top=4
)
Algorithm to delete an element from a stack
1. Declare the stack and top:
stack[1…..M], top;
2. Access the top element:
if (top==0) print “stack is empty”;
else {
x=stack[top];
top=top-1;
}
3. Output: updated list.
Sample Code
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void show(int stack[],int p)
{
printf("nThe stack is:n");
for(int j=1;j<=p;j++)
printf("%d ",stack[j]);
printf("n");
}
int main()
{
int i=0,n,a[50];
printf("Enter maximum size of stack:n");
scanf("%d",&n);
printf("n1.Pushn2.Popn3.Exitn");
while(1)
{
printf("Enter your choice: ");
switch(getche())
{
case '1':if(i<n)
{
printf("nEnter element:");
i++;
scanf("%d",&a[i]);
show(a,i);
}
else
printf("nThe stack is
overflow.n");
break;
case '2':if(i>0)
{i--;
show(a,i);}
else
printf("nThe stack is
underflow.n");
break;
case '3': exit(0);
default: printf("nInvalid Selection.n") ;
break;
}
}
}
Sample Output
Case 1
Enter maximum size of stack:
3
1.Push
2.Pop
3.Exit
Enter your choice: 1
Enter element:5
The stack is:
5
Enter your choice: 1
Enter element:6
The stack is:
5 6
Enter your choice: 1
Enter element:7
The stack is:
5 6 7
Enter your choice: 1
The stack is overflow.
Enter your choice: 3
Case 2:
Enter maximum size of stack:
3
1.Push
2.Pop
3.Exit
Enter your choice: 2
The stack is underflow.
Enter your choice: 1
Enter element:2
The stack is:
2
Enter your choice: 1
Enter element:5
The stack is:
2 5
Enter your choice: 1
Enter element:8
The stack is:
2 5 8
Enter your choice: 1
The stack is overflow.
Enter your choice: 2
The stack is:
2 5
Enter your choice: 2
The stack is:
2
Enter your choice: 2
The stack is:
Enter your choice: 2
The stack is underflow.
Enter your choice: 3

More Related Content

What's hot (20)

Data structure & its types
Data structure & its typesData structure & its types
Data structure & its types
 
Linked list
Linked listLinked list
Linked list
 
Queue - Data Structure - Notes
Queue - Data Structure - NotesQueue - Data Structure - Notes
Queue - Data Structure - Notes
 
Queue AS an ADT (Abstract Data Type)
Queue AS an ADT (Abstract Data Type)Queue AS an ADT (Abstract Data Type)
Queue AS an ADT (Abstract Data Type)
 
Stack
StackStack
Stack
 
single linked list
single linked listsingle linked list
single linked list
 
Dynamic memory allocation in c++
Dynamic memory allocation in c++Dynamic memory allocation in c++
Dynamic memory allocation in c++
 
Constructors and Destructor in C++
Constructors and Destructor in C++Constructors and Destructor in C++
Constructors and Destructor in C++
 
Data Structure and Algorithms Linked List
Data Structure and Algorithms Linked ListData Structure and Algorithms Linked List
Data Structure and Algorithms Linked List
 
Linked list
Linked listLinked list
Linked list
 
Data Structures with C Linked List
Data Structures with C Linked ListData Structures with C Linked List
Data Structures with C Linked List
 
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURE
 
Applications of stack
Applications of stackApplications of stack
Applications of stack
 
Stacks in c++
Stacks in c++Stacks in c++
Stacks in c++
 
linked list in Data Structure, Simple and Easy Tutorial
linked list in Data Structure, Simple and Easy Tutoriallinked list in Data Structure, Simple and Easy Tutorial
linked list in Data Structure, Simple and Easy Tutorial
 
Interrupts
InterruptsInterrupts
Interrupts
 
Infix to postfix conversion
Infix to postfix conversionInfix to postfix conversion
Infix to postfix conversion
 
Circular link list.ppt
Circular link list.pptCircular link list.ppt
Circular link list.ppt
 
trees in data structure
trees in data structure trees in data structure
trees in data structure
 
String functions in C
String functions in CString functions in C
String functions in C
 

Similar to Stack push pop

STACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data StructureSTACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data StructureYaksh Jethva
 
Stack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparationStack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparationRAtna29
 
Stack PPT.pptx
Stack PPT.pptxStack PPT.pptx
Stack PPT.pptxUzmaRizvi5
 
Stack and its applications
Stack and its applicationsStack and its applications
Stack and its applicationsAhsan Mansiv
 
Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manualnikshaikh786
 
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueWhat is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueBalwant Gorad
 
Data Structure.pptx
Data Structure.pptxData Structure.pptx
Data Structure.pptxSajalFayyaz
 
Data Structure and Algorithms Stacks
Data Structure and Algorithms StacksData Structure and Algorithms Stacks
Data Structure and Algorithms StacksManishPrajapati78
 
Stack linked list
Stack linked listStack linked list
Stack linked listbhargav0077
 
Stack and its operation implemented with array new - Copy.pptx
Stack and its operation implemented with array new - Copy.pptxStack and its operation implemented with array new - Copy.pptx
Stack and its operation implemented with array new - Copy.pptxShivam Kumar
 

Similar to Stack push pop (20)

STACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data StructureSTACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data Structure
 
Lect 15-16 Zaheer Abbas
Lect 15-16 Zaheer  AbbasLect 15-16 Zaheer  Abbas
Lect 15-16 Zaheer Abbas
 
Stack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparationStack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparation
 
Unit 3 stack
Unit 3   stackUnit 3   stack
Unit 3 stack
 
Stack PPT.pptx
Stack PPT.pptxStack PPT.pptx
Stack PPT.pptx
 
Stack and its applications
Stack and its applicationsStack and its applications
Stack and its applications
 
04 stacks
04 stacks04 stacks
04 stacks
 
stacks and queues
stacks and queuesstacks and queues
stacks and queues
 
Stack data structure
Stack data structureStack data structure
Stack data structure
 
Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manual
 
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueWhat is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
 
Data Structure.pptx
Data Structure.pptxData Structure.pptx
Data Structure.pptx
 
Queue
QueueQueue
Queue
 
Data Structure and Algorithms Stacks
Data Structure and Algorithms StacksData Structure and Algorithms Stacks
Data Structure and Algorithms Stacks
 
Stack
StackStack
Stack
 
stacks and queues
stacks and queuesstacks and queues
stacks and queues
 
Stack linked list
Stack linked listStack linked list
Stack linked list
 
Stack and its operation implemented with array new - Copy.pptx
Stack and its operation implemented with array new - Copy.pptxStack and its operation implemented with array new - Copy.pptx
Stack and its operation implemented with array new - Copy.pptx
 
Stack - Operations and Applications
Stack - Operations and ApplicationsStack - Operations and Applications
Stack - Operations and Applications
 
STACK1.pptx
STACK1.pptxSTACK1.pptx
STACK1.pptx
 

More from A. S. M. Shafi (20)

2D Transformation in Computer Graphics
2D Transformation in Computer Graphics2D Transformation in Computer Graphics
2D Transformation in Computer Graphics
 
3D Transformation in Computer Graphics
3D Transformation in Computer Graphics3D Transformation in Computer Graphics
3D Transformation in Computer Graphics
 
Projection
ProjectionProjection
Projection
 
2D Transformation
2D Transformation2D Transformation
2D Transformation
 
Line drawing algorithm
Line drawing algorithmLine drawing algorithm
Line drawing algorithm
 
Fragmentation
FragmentationFragmentation
Fragmentation
 
File organization
File organizationFile organization
File organization
 
Bankers algorithm
Bankers algorithmBankers algorithm
Bankers algorithm
 
RR and priority scheduling
RR and priority schedulingRR and priority scheduling
RR and priority scheduling
 
Fcfs and sjf
Fcfs and sjfFcfs and sjf
Fcfs and sjf
 
Applications of stack
Applications of stackApplications of stack
Applications of stack
 
1D Array
1D Array1D Array
1D Array
 
2D array
2D array2D array
2D array
 
Searching
SearchingSearching
Searching
 
Sorting
SortingSorting
Sorting
 
Linked list
Linked listLinked list
Linked list
 
Sum of subset problem
Sum of subset problemSum of subset problem
Sum of subset problem
 
Quick sort
Quick sortQuick sort
Quick sort
 
N queens problem
N queens problemN queens problem
N queens problem
 
MST
MSTMST
MST
 

Recently uploaded

Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 

Recently uploaded (20)

Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 

Stack push pop

  • 1. Stack Stack is a linear list where any element is added at the top of the list and any element is deleted (accessed) from the top of the list. So, for stack an indicator or pointer must be used to indicate or point the top element of the stack. Add operation for a stack is called “push” operation and deletion operation is called “pop” operation. Stack is a LIFO (Last In First Out) structure. That means the element which was added last will be deleted or accessed first. The elements of a stack are added from bottom to top, means push operation is performed from bottom to top. The elements are deleted from top to bottom, which means pop operation is performed from top to bottom. Stack can be implemented using two ways; using array and using linked list. 8 7 6 5 1923 4 1452 3 2315 2 1245 1 1025 (a) Array based stack 40 48 59 67 63 (b) A link based stack Fig. 1: Graphical representation of stack Array Based Stack The stack, which is implemented using array is called array based stack. To create an array based stack, at first we have to declare an array with required size. Push Operation Push operation means to add an element to a stack. Here, we shall use array based stack. So, an array will be treated as a stack. We need an indicator or index identifier to add element to the stack and this indicator will mark the top of the stack. To add an element we have to check whether the array is already full or not. If the array is already full then we cannot add any element, otherwise we can. Here, top is an indicator indicates the top element of the stack and item is an element to be added to the stack, M is the size of the stack (array). Overflow occurs when we try to insert an element into the stack, which is already full. top (top=5 )
  • 2. 6 5 4 D 3 Q 2 F 1 A (a) Before push (b) After push Fig. 2: Pictorial view of push operation Algorithm to add an element to a stack 1. Declare the stack and top: stack[[1…..M], top; 2, Add an item in the stack: if(top<M) { top=top+1; stack[top]=item; } else print “Over Flow”; 3. Output will be the updated stack. Pop Operation Pop operation means to delete (access) an element from a stack. Here, top is an indicator indicates the top element of the stack, M is the size of the array and x is a variable where we access top element of the stack. 6 5 4 D 3 Q 2 F 1 A (a) Before pop (b) After pop Fig. 3: Pictorial view of pop operation 6 5 H 4 D 3 Q 2 F 1 A 6 5 H 4 D 3 Q 2 F 1 A top (top=4 ) top (top=5 ) top (top=5 ) top (top=4 )
  • 3. Algorithm to delete an element from a stack 1. Declare the stack and top: stack[1…..M], top; 2. Access the top element: if (top==0) print “stack is empty”; else { x=stack[top]; top=top-1; } 3. Output: updated list. Sample Code #include<stdio.h> #include<conio.h> #include<stdlib.h> void show(int stack[],int p) { printf("nThe stack is:n"); for(int j=1;j<=p;j++) printf("%d ",stack[j]); printf("n"); } int main() { int i=0,n,a[50]; printf("Enter maximum size of stack:n"); scanf("%d",&n); printf("n1.Pushn2.Popn3.Exitn"); while(1)
  • 4. { printf("Enter your choice: "); switch(getche()) { case '1':if(i<n) { printf("nEnter element:"); i++; scanf("%d",&a[i]); show(a,i); } else printf("nThe stack is overflow.n"); break; case '2':if(i>0) {i--; show(a,i);} else printf("nThe stack is underflow.n"); break; case '3': exit(0); default: printf("nInvalid Selection.n") ; break; } } }
  • 5. Sample Output Case 1 Enter maximum size of stack: 3 1.Push 2.Pop 3.Exit Enter your choice: 1 Enter element:5 The stack is: 5 Enter your choice: 1 Enter element:6 The stack is: 5 6 Enter your choice: 1 Enter element:7 The stack is: 5 6 7 Enter your choice: 1 The stack is overflow. Enter your choice: 3
  • 6. Case 2: Enter maximum size of stack: 3 1.Push 2.Pop 3.Exit Enter your choice: 2 The stack is underflow. Enter your choice: 1 Enter element:2 The stack is: 2 Enter your choice: 1 Enter element:5 The stack is: 2 5 Enter your choice: 1 Enter element:8 The stack is: 2 5 8 Enter your choice: 1 The stack is overflow. Enter your choice: 2 The stack is:
  • 7. 2 5 Enter your choice: 2 The stack is: 2 Enter your choice: 2 The stack is: Enter your choice: 2 The stack is underflow. Enter your choice: 3