SlideShare a Scribd company logo
STACK 
SUBMITTED BY: 
Archie Jamwal 
SUBMITTED TO: 
Mrs. Ruchi Gupta
DATA 
STRUCTURE 
LINEAR DATA 
STRUCTURE 
NON LINEAR 
DATA 
STRUCTURE 
ARRAY QUEUE STACK
What is Linear Data Structure 
In linear data structure, data is arranged 
in linear sequence. 
 Data items can be traversed in a single 
run. 
 In linear data structure elements are 
accessed or placed in contiguous(together 
in sequence) memory location.
WHAT Is 
 A stack is called a last-in-first-out (LIFO) 
collection. This means that the last thing 
we added (pushed) is the first thing that 
gets pulled (popped) off. 
 A stack is a sequence of items that are 
accessible at only one end of the sequence.
EXAMPLES OF STACK:
Operations that can be performed 
on STACK: 
 PUSH. 
 POP.
PUSH : It is used to insert items into the stack. 
POP: It is used to delete items from stack. 
TOP: It represents the current location of data 
in stack.
ALGORITHM OF INSERTION IN 
STACK: (PUSH) 
1. Insertion(a,top,item,max) 
2. If top=max then 
print ‘STACK OVERFLOW’ 
exit 
else 
3. top=top+1 
end if 
4. a[top]=item 
5. Exit
ALGORITHM OF DELETION IN 
STACK: (POP) 
1. Deletion(a,top,item) 
2. If top=0 then 
print ‘STACK UNDERFLOW’ 
exit 
else 
3. item=a[top] 
end if 
4. top=top-1 
5. Exit
ALGORITHM OF DISPLAY IN 
STACK: 
1.Display(top,i,a[i]) 
2.If top=0 then 
Print ‘STACK EMPTY’ 
Exit 
Else 
3.For i=top to 0 
Print a[i] 
End for 
4.exit
APPLICATIONS OF STACKS ARE: 
I. Reversing Strings: 
• A simple application of stack is reversing strings. 
To reverse a string , the characters of string are 
pushed onto the stack one by one as the string 
is read from left to right. 
• Once all the characters 
of string are pushed onto stack, they are 
popped one by one. Since the character last 
pushed in comes out first, subsequent pop 
operation results in the reversal of the string.
For example: 
To reverse the string ‘REVERSE’ the string is 
read from left to right and its characters are 
pushed . LIKE: 
onto a stack.
II. Checking the validity of an expression 
containing nested parenthesis: 
• Stacks are also used to check whether a given 
arithmetic expressions containing nested 
parenthesis is properly parenthesized. 
• The program for checking the validity of an 
expression verifies that for each left parenthesis 
braces or bracket ,there is a corresponding 
closing symbol and symbols are appropriately 
nested.
For example: 
VALID INPUTS INVALID INPUTS 
{ } 
{ ( } 
( { [ ] } ) 
( [ ( ( ) ] ) 
{ [ ] ( ) } 
{ } [ ] ) 
[ { ( { } [ ] ( { 
[ { ) } ( ] } ] 
})}]
III. Evaluating arithmetic expressions: 
INFIX notation: 
The general way of writing arithmetic 
expressions is known as infix notation. 
e.g, (a+b) 
PREFIX notation: 
e.g, +AB 
POSTFIX notation: 
e.g: AB+
Conversion of INFIX to POSTFIX conversion: 
Example: 2+(4-1)*3 step1 
2+41-*3 step2 
2+41-3* step3 
241-3*+ step4
CURRENT 
SYMBOL 
ACTION 
PERFORMED 
STACK STATUS POSTFIX 
EXPRESSION 
( PUSH C C 2 
2 2 
+ PUSH + (+ 2 
( PUSH ( (+( 24 
4 24 
- PUSH - (+(- 241 
1 POP 241- 
) (+ 241- 
* PUSH * (+* 241- 
3 241-3 
POP * 241-3* 
POP + 241-3*+ 
) 
CONVERSION OF INFIX INTO POSTFIX 
2+(4-1)*3 into 241-3*+
THANK YOU 
Ad

More Related Content

What's hot (20)

Infix to postfix conversion
Infix to postfix conversionInfix to postfix conversion
Infix to postfix conversion
Then Murugeshwari
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applications
somendra kumar
 
Data Structure (Queue)
Data Structure (Queue)Data Structure (Queue)
Data Structure (Queue)
Adam Mukharil Bachtiar
 
B and B+ tree
B and B+ treeB and B+ tree
B and B+ tree
Ashish Arun
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure
shameen khan
 
Linked list
Linked listLinked list
Linked list
akshat360
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
anooppjoseph
 
BINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptBINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.ppt
SeethaDinesh
 
single linked list
single linked listsingle linked list
single linked list
Sathasivam Rangasamy
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
Poojith Chowdhary
 
Stack
StackStack
Stack
Zaid Shabbir
 
Stack
StackStack
Stack
srihariyenduri
 
Data structure by Digvijay
Data structure by DigvijayData structure by Digvijay
Data structure by Digvijay
Digvijay Singh Karakoti
 
Stacks in c++
Stacks in c++Stacks in c++
Stacks in c++
Vineeta Garg
 
Arrays
ArraysArrays
Arrays
SARITHA REDDY
 
Data types in python
Data types in pythonData types in python
Data types in python
RaginiJain21
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
Janki Shah
 
Doubly Linked List || Operations || Algorithms
Doubly Linked List || Operations || AlgorithmsDoubly Linked List || Operations || Algorithms
Doubly Linked List || Operations || Algorithms
Shubham Sharma
 
Presentation on queue
Presentation on queuePresentation on queue
Presentation on queue
Rojan Pariyar
 
List in Python
List in PythonList in Python
List in Python
Siddique Ibrahim
 

Similar to STACKS IN DATASTRUCTURE (20)

STACK AND ITS OPERATIONS IN DATA STRUCTURES.pptx
STACK AND ITS OPERATIONS IN DATA STRUCTURES.pptxSTACK AND ITS OPERATIONS IN DATA STRUCTURES.pptx
STACK AND ITS OPERATIONS IN DATA STRUCTURES.pptx
KALPANAC20
 
Stack_Data_Structure.pptx
Stack_Data_Structure.pptxStack_Data_Structure.pptx
Stack_Data_Structure.pptx
sandeep54552
 
Stack_Overview_Implementation_WithVode.pptx
Stack_Overview_Implementation_WithVode.pptxStack_Overview_Implementation_WithVode.pptx
Stack_Overview_Implementation_WithVode.pptx
chandankumar364348
 
Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manual
nikshaikh786
 
DS-UNIT 3 FINAL.pptx
DS-UNIT 3 FINAL.pptxDS-UNIT 3 FINAL.pptx
DS-UNIT 3 FINAL.pptx
prakashvs7
 
Stacks Data structure.pptx
Stacks Data structure.pptxStacks Data structure.pptx
Stacks Data structure.pptx
line24arts
 
stack-Intro.pptx
stack-Intro.pptxstack-Intro.pptx
stack-Intro.pptx
DEEPAK948083
 
Data Structures And Algorithms(stacks queues)
Data Structures And Algorithms(stacks queues)Data Structures And Algorithms(stacks queues)
Data Structures And Algorithms(stacks queues)
lahariit406
 
Stack,queue and linked list data structure.pptx
Stack,queue and linked list data structure.pptxStack,queue and linked list data structure.pptx
Stack,queue and linked list data structure.pptx
yukti266975
 
Stacks
StacksStacks
Stacks
Sadaf Ismail
 
Data Structures: Stacks (Part 1)
Data Structures: Stacks (Part 1)Data Structures: Stacks (Part 1)
Data Structures: Stacks (Part 1)
Ramachandra Adiga G
 
Unit 3 stack
Unit   3 stackUnit   3 stack
Unit 3 stack
Dabbal Singh Mahara
 
Stack ppt file of Stack DSA For lab in the lab of DSA lecture and Lab.ppt
Stack ppt file of Stack DSA For lab in the lab of DSA lecture and Lab.pptStack ppt file of Stack DSA For lab in the lab of DSA lecture and Lab.ppt
Stack ppt file of Stack DSA For lab in the lab of DSA lecture and Lab.ppt
aamirali1061a
 
Stack data structures with definition and code
Stack data structures with definition and codeStack data structures with definition and code
Stack data structures with definition and code
bansidharj11
 
stack-111104232459-phpapp02.pdf
stack-111104232459-phpapp02.pdfstack-111104232459-phpapp02.pdf
stack-111104232459-phpapp02.pdf
Kalpana Mohan
 
Stacks
StacksStacks
Stacks
sweta dargad
 
6 - STACKS in Data Structure and Algorithm.pptx
6 - STACKS in Data Structure and Algorithm.pptx6 - STACKS in Data Structure and Algorithm.pptx
6 - STACKS in Data Structure and Algorithm.pptx
RahulRaj493025
 
Stack - Data Structure - Notes
Stack - Data Structure - NotesStack - Data Structure - Notes
Stack - Data Structure - Notes
Omprakash Chauhan
 
week 7,8,10,11 alll files included from .ppt
week 7,8,10,11 alll files included from .pptweek 7,8,10,11 alll files included from .ppt
week 7,8,10,11 alll files included from .ppt
LidetAdmassu
 
Stack and its operations, Queue and its operations
Stack and its operations, Queue and its operationsStack and its operations, Queue and its operations
Stack and its operations, Queue and its operations
poongothai11
 
STACK AND ITS OPERATIONS IN DATA STRUCTURES.pptx
STACK AND ITS OPERATIONS IN DATA STRUCTURES.pptxSTACK AND ITS OPERATIONS IN DATA STRUCTURES.pptx
STACK AND ITS OPERATIONS IN DATA STRUCTURES.pptx
KALPANAC20
 
Stack_Data_Structure.pptx
Stack_Data_Structure.pptxStack_Data_Structure.pptx
Stack_Data_Structure.pptx
sandeep54552
 
Stack_Overview_Implementation_WithVode.pptx
Stack_Overview_Implementation_WithVode.pptxStack_Overview_Implementation_WithVode.pptx
Stack_Overview_Implementation_WithVode.pptx
chandankumar364348
 
Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manual
nikshaikh786
 
DS-UNIT 3 FINAL.pptx
DS-UNIT 3 FINAL.pptxDS-UNIT 3 FINAL.pptx
DS-UNIT 3 FINAL.pptx
prakashvs7
 
Stacks Data structure.pptx
Stacks Data structure.pptxStacks Data structure.pptx
Stacks Data structure.pptx
line24arts
 
Data Structures And Algorithms(stacks queues)
Data Structures And Algorithms(stacks queues)Data Structures And Algorithms(stacks queues)
Data Structures And Algorithms(stacks queues)
lahariit406
 
Stack,queue and linked list data structure.pptx
Stack,queue and linked list data structure.pptxStack,queue and linked list data structure.pptx
Stack,queue and linked list data structure.pptx
yukti266975
 
Data Structures: Stacks (Part 1)
Data Structures: Stacks (Part 1)Data Structures: Stacks (Part 1)
Data Structures: Stacks (Part 1)
Ramachandra Adiga G
 
Stack ppt file of Stack DSA For lab in the lab of DSA lecture and Lab.ppt
Stack ppt file of Stack DSA For lab in the lab of DSA lecture and Lab.pptStack ppt file of Stack DSA For lab in the lab of DSA lecture and Lab.ppt
Stack ppt file of Stack DSA For lab in the lab of DSA lecture and Lab.ppt
aamirali1061a
 
Stack data structures with definition and code
Stack data structures with definition and codeStack data structures with definition and code
Stack data structures with definition and code
bansidharj11
 
stack-111104232459-phpapp02.pdf
stack-111104232459-phpapp02.pdfstack-111104232459-phpapp02.pdf
stack-111104232459-phpapp02.pdf
Kalpana Mohan
 
6 - STACKS in Data Structure and Algorithm.pptx
6 - STACKS in Data Structure and Algorithm.pptx6 - STACKS in Data Structure and Algorithm.pptx
6 - STACKS in Data Structure and Algorithm.pptx
RahulRaj493025
 
Stack - Data Structure - Notes
Stack - Data Structure - NotesStack - Data Structure - Notes
Stack - Data Structure - Notes
Omprakash Chauhan
 
week 7,8,10,11 alll files included from .ppt
week 7,8,10,11 alll files included from .pptweek 7,8,10,11 alll files included from .ppt
week 7,8,10,11 alll files included from .ppt
LidetAdmassu
 
Stack and its operations, Queue and its operations
Stack and its operations, Queue and its operationsStack and its operations, Queue and its operations
Stack and its operations, Queue and its operations
poongothai11
 
Ad

Recently uploaded (20)

Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Library Association of Ireland
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
Operations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdfOperations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdf
Arab Academy for Science, Technology and Maritime Transport
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessUltimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Mark Soia
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACYUNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
DR.PRISCILLA MARY J
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdfBiophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
PKLI-Institute of Nursing and Allied Health Sciences Lahore , Pakistan.
 
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Library Association of Ireland
 
The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...
Sandeep Swamy
 
SPRING FESTIVITIES - UK AND USA -
SPRING FESTIVITIES - UK AND USA            -SPRING FESTIVITIES - UK AND USA            -
SPRING FESTIVITIES - UK AND USA -
Colégio Santa Teresinha
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
Unit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdfUnit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdf
KanchanPatil34
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Library Association of Ireland
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessUltimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Mark Soia
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACYUNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
DR.PRISCILLA MARY J
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Library Association of Ireland
 
The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...
Sandeep Swamy
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
Unit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdfUnit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdf
KanchanPatil34
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
Ad

STACKS IN DATASTRUCTURE

  • 1. STACK SUBMITTED BY: Archie Jamwal SUBMITTED TO: Mrs. Ruchi Gupta
  • 2. DATA STRUCTURE LINEAR DATA STRUCTURE NON LINEAR DATA STRUCTURE ARRAY QUEUE STACK
  • 3. What is Linear Data Structure In linear data structure, data is arranged in linear sequence.  Data items can be traversed in a single run.  In linear data structure elements are accessed or placed in contiguous(together in sequence) memory location.
  • 4. WHAT Is  A stack is called a last-in-first-out (LIFO) collection. This means that the last thing we added (pushed) is the first thing that gets pulled (popped) off.  A stack is a sequence of items that are accessible at only one end of the sequence.
  • 6. Operations that can be performed on STACK:  PUSH.  POP.
  • 7. PUSH : It is used to insert items into the stack. POP: It is used to delete items from stack. TOP: It represents the current location of data in stack.
  • 8. ALGORITHM OF INSERTION IN STACK: (PUSH) 1. Insertion(a,top,item,max) 2. If top=max then print ‘STACK OVERFLOW’ exit else 3. top=top+1 end if 4. a[top]=item 5. Exit
  • 9. ALGORITHM OF DELETION IN STACK: (POP) 1. Deletion(a,top,item) 2. If top=0 then print ‘STACK UNDERFLOW’ exit else 3. item=a[top] end if 4. top=top-1 5. Exit
  • 10. ALGORITHM OF DISPLAY IN STACK: 1.Display(top,i,a[i]) 2.If top=0 then Print ‘STACK EMPTY’ Exit Else 3.For i=top to 0 Print a[i] End for 4.exit
  • 11. APPLICATIONS OF STACKS ARE: I. Reversing Strings: • A simple application of stack is reversing strings. To reverse a string , the characters of string are pushed onto the stack one by one as the string is read from left to right. • Once all the characters of string are pushed onto stack, they are popped one by one. Since the character last pushed in comes out first, subsequent pop operation results in the reversal of the string.
  • 12. For example: To reverse the string ‘REVERSE’ the string is read from left to right and its characters are pushed . LIKE: onto a stack.
  • 13. II. Checking the validity of an expression containing nested parenthesis: • Stacks are also used to check whether a given arithmetic expressions containing nested parenthesis is properly parenthesized. • The program for checking the validity of an expression verifies that for each left parenthesis braces or bracket ,there is a corresponding closing symbol and symbols are appropriately nested.
  • 14. For example: VALID INPUTS INVALID INPUTS { } { ( } ( { [ ] } ) ( [ ( ( ) ] ) { [ ] ( ) } { } [ ] ) [ { ( { } [ ] ( { [ { ) } ( ] } ] })}]
  • 15. III. Evaluating arithmetic expressions: INFIX notation: The general way of writing arithmetic expressions is known as infix notation. e.g, (a+b) PREFIX notation: e.g, +AB POSTFIX notation: e.g: AB+
  • 16. Conversion of INFIX to POSTFIX conversion: Example: 2+(4-1)*3 step1 2+41-*3 step2 2+41-3* step3 241-3*+ step4
  • 17. CURRENT SYMBOL ACTION PERFORMED STACK STATUS POSTFIX EXPRESSION ( PUSH C C 2 2 2 + PUSH + (+ 2 ( PUSH ( (+( 24 4 24 - PUSH - (+(- 241 1 POP 241- ) (+ 241- * PUSH * (+* 241- 3 241-3 POP * 241-3* POP + 241-3*+ ) CONVERSION OF INFIX INTO POSTFIX 2+(4-1)*3 into 241-3*+