SlideShare uma empresa Scribd logo
1 de 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);
}

Mais conteúdo relacionado

Mais procurados (20)

Stacks
StacksStacks
Stacks
 
Stack of Data structure
Stack of Data structureStack of Data structure
Stack of Data structure
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
 
Stacks in DATA STRUCTURE
Stacks in DATA STRUCTUREStacks in DATA STRUCTURE
Stacks in DATA STRUCTURE
 
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURE
 
Data Structure (Queue)
Data Structure (Queue)Data Structure (Queue)
Data Structure (Queue)
 
Stack and its Applications : Data Structures ADT
Stack and its Applications : Data Structures ADTStack and its Applications : Data Structures ADT
Stack and its Applications : Data Structures ADT
 
Stack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi LecturerStack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi Lecturer
 
Stacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURESStacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURES
 
Queue ppt
Queue pptQueue ppt
Queue ppt
 
Stacks,queues,linked-list
Stacks,queues,linked-listStacks,queues,linked-list
Stacks,queues,linked-list
 
sorting and its types
sorting and its typessorting and its types
sorting and its types
 
Data Structure (Stack)
Data Structure (Stack)Data Structure (Stack)
Data Structure (Stack)
 
Data structure Stack
Data structure StackData structure Stack
Data structure Stack
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Queues
QueuesQueues
Queues
 
stack & queue
stack & queuestack & queue
stack & queue
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
 
Stack - Operations and Applications
Stack - Operations and ApplicationsStack - Operations and Applications
Stack - Operations and Applications
 
Stack and Queue
Stack and Queue Stack and Queue
Stack and Queue
 

Destaque

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
 
Stack Data Structure & It's Application
Stack Data Structure & It's Application Stack Data Structure & It's Application
Stack Data Structure & It's Application Tech_MX
 
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
 

Destaque (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
 
Stack Data Structure & It's Application
Stack Data Structure & It's Application Stack Data Structure & It's Application
Stack Data Structure & It's Application
 
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
 

Semelhante a 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
 

Semelhante a 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
 
Stacks in c++
Stacks in c++Stacks in c++
Stacks in c++
 
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
 

Mais de Digvijay Singh Karakoti

Mais de 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]
 

Último

Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
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
 

Último (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
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
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
 

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); }