SlideShare a Scribd company logo
1 of 13
STACK
REPRESENTATION

BY- DIGVIJAY SINGH KARAKOTI
WHAT IS STACK?
Stack is the non-linear non-primitive data
structure or an ordered pair of elements.
A Stack is a LIFO structure which follows the
principal of “LAST IN FIRST OUT”, which
depicts the insertion of last element in the
stack and deletion of first element from the
stack from one end called “TOP” of the stack.
Some real life examples of
Stack
APPLICATIONS OF STACK
 Expression evaluation
 Infix, Prefix and Postfix Notation
 Expression conversion

 Memory Management
 Recursion
OPERATIONS PERFORMED IN
STACK
The m or oper at i ons per f or m by
aj
ed
st ack
ar e:
 PU ( ) – Thi s oper at i on i s used
SH
t o i nser t t he el em
ent i nt o t he
st ack. So, i t i s al so know as
n
“I N TI O ” oper at i on.
SER N
 PO ) - Thi s oper at i on i s used
P(
t o del et e or r et r i eve t he el em
ent
PUSH OPERATION
This function will add elements/items into
the stack. Whenever we add an element
into the stack the pointer TOP gets
incremented as:TOP+1 or TOP++
This is used to show the position of the
element in the stack.
PUSH operation on stack is to add values into the stack. Let us
assume that 5 items 30, 20, 25, 10 and 40 are to be placed on
the stack. The items can be inserted one by one as shown in
following figure:-
ALGORITHM FOR PUSH
OPERATIONITEM, TOP)
PUSH(MAXSTK,
STEP 1: If TOP = MAXSTK THEN [Stack already
filled?]
Print "OVERFLOW"
Go to step 4
End if
STEP 2: TOP = TOP + 1 [Increase TOP by 1]

STEP 3: Set STK[TOP] = ITEM [Insert ITEM in
new TOP position]
Program implementation of PUSH
operation
void push()
{ int item;
If(TOP==maxsize-1)
{ printf(“n Stack is full”);
getch();
exit(0);
}
else
{ printf(“n Enter the element to be inserted”);
scanf(“%d”, &item);
TOP=TOP+1;
stack[TOP]=item;
}
}
POP OPERATION
This function will delete elements/items
from the stack. Whenever we add an
element into the stack the pointer TOP
gets decremented as:TOP-1 or TOP-This is used to show the position of the
element in the stack
POP operation on stack is to delete or retrieve values from the
stack. Let us assume that 4 items 15, 12, 10 and 5 are to be
deleted from the stack. The items can be deleted one by one as
shown in following figure:-

Figure. Deletion operations
ALGORITHM FOR POP
OPERATION
POP[STACK,TOP,ITEM]
STEP 1: If TOP=0
Print ”Underflow”
STEP 2: Set ITEM=STACK[TOP]
STEP 3: Set TOP=TOP-1
STEP 4: Return
Program implementation of POP
operation
int pop()
{ int item;
if(TOP==-1)
{ printf(“n Stack is empty”);
getch();
exit(0);
}
else
{ item=stack[TOP];
TOP=TOP-1;
printf(“n Item deleted is= %d”, item);
}
return(item);
}

More Related Content

What's hot (20)

Stack
StackStack
Stack
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
 
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMS
 
Stack Data Structure & It's Application
Stack Data Structure & It's Application Stack Data Structure & It's Application
Stack Data Structure & It's Application
 
Data Structure (Queue)
Data Structure (Queue)Data Structure (Queue)
Data Structure (Queue)
 
Infix to postfix conversion
Infix to postfix conversionInfix to postfix conversion
Infix to postfix conversion
 
Doubly linked list (animated)
Doubly linked list (animated)Doubly linked list (animated)
Doubly linked list (animated)
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
 
stack
stackstack
stack
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure
 
Queue ppt
Queue pptQueue ppt
Queue ppt
 
single linked list
single linked listsingle linked list
single linked list
 
Linear search-and-binary-search
Linear search-and-binary-searchLinear search-and-binary-search
Linear search-and-binary-search
 
Stack_Data_Structure.pptx
Stack_Data_Structure.pptxStack_Data_Structure.pptx
Stack_Data_Structure.pptx
 
stack & queue
stack & queuestack & queue
stack & queue
 
heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort Algorithm
 
Queues
QueuesQueues
Queues
 
Data Structures- Part5 recursion
Data Structures- Part5 recursionData Structures- Part5 recursion
Data Structures- Part5 recursion
 
Stack a Data Structure
Stack a Data StructureStack a Data Structure
Stack a Data Structure
 
Stacks in c++
Stacks in c++Stacks in c++
Stacks in c++
 

Viewers also liked

STAR: Stack Trace based Automatic Crash Reproduction
STAR: Stack Trace based Automatic Crash ReproductionSTAR: Stack Trace based Automatic Crash Reproduction
STAR: Stack Trace based Automatic Crash ReproductionSung Kim
 
Stacks Implementation and Examples
Stacks Implementation and ExamplesStacks Implementation and Examples
Stacks Implementation and Examplesgreatqadirgee4u
 
Queue in C, Queue Real Life of Example
Queue in C, Queue Real Life of ExampleQueue in C, Queue Real Life of Example
Queue in C, Queue Real Life of ExampleHitesh Kumar
 
Digital Image Processing - Image Restoration
Digital Image Processing - Image RestorationDigital Image Processing - Image Restoration
Digital Image Processing - Image RestorationMathankumar S
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data StructureZidny Nafan
 
How To Write Effective Case Scenarios
How To Write Effective Case ScenariosHow To Write Effective Case Scenarios
How To Write Effective Case ScenariosJustina Sharma
 
2015 Upload Campaigns Calendar - SlideShare
2015 Upload Campaigns Calendar - SlideShare2015 Upload Campaigns Calendar - SlideShare
2015 Upload Campaigns Calendar - SlideShareSlideShare
 
What to Upload to SlideShare
What to Upload to SlideShareWhat to Upload to SlideShare
What to Upload to SlideShareSlideShare
 
Getting Started With SlideShare
Getting Started With SlideShareGetting Started With SlideShare
Getting Started With SlideShareSlideShare
 

Viewers also liked (10)

STAR: Stack Trace based Automatic Crash Reproduction
STAR: Stack Trace based Automatic Crash ReproductionSTAR: Stack Trace based Automatic Crash Reproduction
STAR: Stack Trace based Automatic Crash Reproduction
 
Stacks Implementation and Examples
Stacks Implementation and ExamplesStacks Implementation and Examples
Stacks Implementation and Examples
 
U3.stack queue
U3.stack queueU3.stack queue
U3.stack queue
 
Queue in C, Queue Real Life of Example
Queue in C, Queue Real Life of ExampleQueue in C, Queue Real Life of Example
Queue in C, Queue Real Life of Example
 
Digital Image Processing - Image Restoration
Digital Image Processing - Image RestorationDigital Image Processing - Image Restoration
Digital Image Processing - Image Restoration
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
How To Write Effective Case Scenarios
How To Write Effective Case ScenariosHow To Write Effective Case Scenarios
How To Write Effective Case Scenarios
 
2015 Upload Campaigns Calendar - SlideShare
2015 Upload Campaigns Calendar - SlideShare2015 Upload Campaigns Calendar - SlideShare
2015 Upload Campaigns Calendar - SlideShare
 
What to Upload to SlideShare
What to Upload to SlideShareWhat to Upload to SlideShare
What to Upload to SlideShare
 
Getting Started With SlideShare
Getting Started With SlideShareGetting Started With SlideShare
Getting Started With SlideShare
 

Similar to Data structure by Digvijay

Explain what does the following function do void foo (Stack s) { .pdf
Explain what does the following function do  void foo (Stack s)  {  .pdfExplain what does the following function do  void foo (Stack s)  {  .pdf
Explain what does the following function do void foo (Stack s) { .pdfmeerobertsonheyde608
 
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 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
 
Applicationofstack by Ali F.RAshid
Applicationofstack  by Ali F.RAshid Applicationofstack  by Ali F.RAshid
Applicationofstack by Ali F.RAshid ali rashid
 
Application of Stack - Yadraj Meena
Application of Stack - Yadraj MeenaApplication of Stack - Yadraj Meena
Application of Stack - Yadraj MeenaDipayan Sarkar
 
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
 
Stack operation algorithms with example
Stack operation algorithms with exampleStack operation algorithms with example
Stack operation algorithms with exampleNamanKikani
 
Data structures stacks
Data structures   stacksData structures   stacks
Data structures stacksmaamir farooq
 
Chapter 5 Stack and Queue.pdf
Chapter 5 Stack and Queue.pdfChapter 5 Stack and Queue.pdf
Chapter 5 Stack and Queue.pdfGirT2
 

Similar to Data structure by Digvijay (20)

Explain what does the following function do void foo (Stack s) { .pdf
Explain what does the following function do  void foo (Stack s)  {  .pdfExplain what does the following function do  void foo (Stack s)  {  .pdf
Explain what does the following function do void foo (Stack s) { .pdf
 
STACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data StructureSTACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data Structure
 
Stack data structure
Stack data structureStack data structure
Stack data structure
 
04 stacks
04 stacks04 stacks
04 stacks
 
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
 
Stack
StackStack
Stack
 
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
 
Lect 15-16 Zaheer Abbas
Lect 15-16 Zaheer  AbbasLect 15-16 Zaheer  Abbas
Lect 15-16 Zaheer Abbas
 
Stack and its operations
Stack and its operationsStack and its operations
Stack and its operations
 
Applicationofstack by Ali F.RAshid
Applicationofstack  by Ali F.RAshid Applicationofstack  by Ali F.RAshid
Applicationofstack by Ali F.RAshid
 
Application of Stack - Yadraj Meena
Application of Stack - Yadraj MeenaApplication of Stack - Yadraj Meena
Application of Stack - Yadraj Meena
 
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
 
Stack operation algorithms with example
Stack operation algorithms with exampleStack operation algorithms with example
Stack operation algorithms with example
 
stacks and queues
stacks and queuesstacks and queues
stacks and queues
 
DATA STRUCTURE - STACK
DATA STRUCTURE - STACKDATA STRUCTURE - STACK
DATA STRUCTURE - STACK
 
Data structures stacks
Data structures   stacksData structures   stacks
Data structures stacks
 
Ds stacks
Ds stacksDs stacks
Ds stacks
 
stacks and queues
stacks and queuesstacks and queues
stacks and queues
 
Chapter 5 Stack and Queue.pdf
Chapter 5 Stack and Queue.pdfChapter 5 Stack and Queue.pdf
Chapter 5 Stack and Queue.pdf
 

More from Digvijay Singh Karakoti

More from Digvijay Singh Karakoti (8)

Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++
 
Computer Hardware Basics (Components to be understand)
Computer Hardware Basics (Components to be understand)Computer Hardware Basics (Components to be understand)
Computer Hardware Basics (Components to be understand)
 
Digital signature
Digital signatureDigital signature
Digital signature
 
Simon’s model for Decision Making Process
Simon’s model for Decision Making ProcessSimon’s model for Decision Making Process
Simon’s model for Decision Making Process
 
Operations Research-2nd edition
Operations Research-2nd editionOperations Research-2nd edition
Operations Research-2nd edition
 
Root Of The Equations [By- Digvijay]
Root Of The Equations [By- Digvijay]Root Of The Equations [By- Digvijay]
Root Of The Equations [By- Digvijay]
 
DMA presentation [By- Digvijay]
DMA presentation [By- Digvijay]DMA presentation [By- Digvijay]
DMA presentation [By- Digvijay]
 
General OOP concept [by-Digvijay]
General OOP concept [by-Digvijay]General OOP concept [by-Digvijay]
General OOP concept [by-Digvijay]
 

Recently uploaded

Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxUmeshTimilsina1
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 

Recently uploaded (20)

Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 

Data structure by Digvijay

  • 2. WHAT IS STACK? Stack is the non-linear non-primitive data structure or an ordered pair of elements. A Stack is a LIFO structure which follows the principal of “LAST IN FIRST OUT”, which depicts the insertion of last element in the stack and deletion of first element from the stack from one end called “TOP” of the stack.
  • 3. Some real life examples of Stack
  • 4. APPLICATIONS OF STACK  Expression evaluation  Infix, Prefix and Postfix Notation  Expression conversion  Memory Management  Recursion
  • 5. OPERATIONS PERFORMED IN STACK The m or oper at i ons per f or m by aj ed st ack ar e:  PU ( ) – Thi s oper at i on i s used SH t o i nser t t he el em ent i nt o t he st ack. So, i t i s al so know as n “I N TI O ” oper at i on. SER N  PO ) - Thi s oper at i on i s used P( t o del et e or r et r i eve t he el em ent
  • 6. PUSH OPERATION This function will add elements/items into the stack. Whenever we add an element into the stack the pointer TOP gets incremented as:TOP+1 or TOP++ This is used to show the position of the element in the stack.
  • 7. PUSH operation on stack is to add values into the stack. Let us assume that 5 items 30, 20, 25, 10 and 40 are to be placed on the stack. The items can be inserted one by one as shown in following figure:-
  • 8. ALGORITHM FOR PUSH OPERATIONITEM, TOP) PUSH(MAXSTK, STEP 1: If TOP = MAXSTK THEN [Stack already filled?] Print "OVERFLOW" Go to step 4 End if STEP 2: TOP = TOP + 1 [Increase TOP by 1] STEP 3: Set STK[TOP] = ITEM [Insert ITEM in new TOP position]
  • 9. Program implementation of PUSH operation void push() { int item; If(TOP==maxsize-1) { printf(“n Stack is full”); getch(); exit(0); } else { printf(“n Enter the element to be inserted”); scanf(“%d”, &item); TOP=TOP+1; stack[TOP]=item; } }
  • 10. POP OPERATION This function will delete elements/items from the stack. Whenever we add an element into the stack the pointer TOP gets decremented as:TOP-1 or TOP-This is used to show the position of the element in the stack
  • 11. POP operation on stack is to delete or retrieve values from the stack. Let us assume that 4 items 15, 12, 10 and 5 are to be deleted from the stack. The items can be deleted one by one as shown in following figure:- Figure. Deletion operations
  • 12. ALGORITHM FOR POP OPERATION POP[STACK,TOP,ITEM] STEP 1: If TOP=0 Print ”Underflow” STEP 2: Set ITEM=STACK[TOP] STEP 3: Set TOP=TOP-1 STEP 4: Return
  • 13. Program implementation of POP operation int pop() { int item; if(TOP==-1) { printf(“n Stack is empty”); getch(); exit(0); } else { item=stack[TOP]; TOP=TOP-1; printf(“n Item deleted is= %d”, item); } return(item); }