SlideShare a Scribd company logo
Linked Stack and Linked Queue
Chapter 7
Outline
● Introduction
– Linked Stacks
– Linked Queues
● Operations on Linked Stacks and Linked Queues
– Linked Stack Operations
– Linked Queue Operations
– Algorithms for Push/Pop operations on a Linked Stack
– Algorithms for Insert/Delete operations in a Linked Queue
● Dynamic memory management and Linked Stacks
● Implementation of Linked Representations
● Applications
– Balancing Symbols
– Polynomial Representation
Introduction
● A linked stack is a linear list of elements commonly
implemented as a singly linked list whose start pointer
performs the role of the top pointer of a stack
● A linked queue is also a linear list of elements
commonly implemented as a singly linked list but with two
pointers viz., FRONT and REAR. The start pointer of the
singly linked list plays the role of FRONT while the pointer
to the last node is set to play the role of REAR.
Implementing Stack and Queue Using Linked List
6
1
2
3
4
5
A
B
E
D
G
F
Top = 6
1 2 3 4 5 6
B C
Front=1 Rear = 3
Stack[1:6] Queue[1:6]
B C G H
stack
Top
B C G H
queue
front rear
Operations of Linked Stack and
Linked Queue
Operations on Linked Stack
● Push
– GETNODE(X)
– LINK(X) = Top
– Top = X
B C G H
stack
Top
C
X
Algorithm: Push item ITEM into a linked stack S with top
pointer TOP
procedure PUSH_LINKSTACK (TOP, ITEM)
/* Insert ITEM into stack */
Call GETNODE(X)
DATA(X) = ITEM /*frame node for ITEM */
LINK(X) = TOP /* insert node X into stack */
TOP = X /* reset TOP pointer */
end PUSH_LINKSTACK.
● Pop
– Temp = Top
– Item = DATA(Top)
– Top = LINK(TOP)
– RETURN(Temp)
B C G H
stack
Top
Temp
Algorithm: Pop from a linked stack S and output the
element through ITEM
procedure POP_LINKSTACK(TOP, ITEM)
/* pop element from stack and set ITEM to
the element */
if (TOP = 0) then call LINKSTACK_EMPTY
/* check if linked stack is empty */
else { TEMP = TOP
ITEM = DATA(TOP)
TOP = LINK(TOP)
}
call RETURN(TEMP) ;
end POP_LINKSTACK.
● Enqueue
– LINK(rear) = X
– Rear = X
B C G H
queue
front
rear
A
X
B C G H
queue
front rear
Algorithm: Enqueue an ITEM into a linked list queue Q
procedure INSERT_LINKQUEUE(FRONT,REAR,ITEM)
Call GETNODE(X);
DATA(X)= ITEM;
LINK(X)= NIL; /* Node with ITEM is ready to be
inserted into Q */
if (Queue = 0) then
•Queue = FRONT = REAR = X;
/* If Q is empty then ITEM is the
first element in the queue Q
else {LINK(REAR) = X;
REAR = X
}
end INSERT_LINKQUEUE.
● Dequeue
– Temp = front
– front = Link(front)
– Item = DATA(Temp)
– RETURN(Temp)
B C G H
queue
front rear
Temp
Algorithm: Dequeue an element from the linked queue Q
procedure DELETE_LINKQUEUE (FRONT,ITEM)
if (FRONT = 0) then call LINKQUEUE_EMPTY;
/* Test condition to avoid deletion in an empty
queue */
else {TEMP = FRONT;
ITEM = DATA (TEMP);
FRONT = LINK (TEMP);
}
call RETURN (TEMP); /* return the node TEMP to
the free pool */
end DELETE_LINKQUEUE.
Implementing Linked list Queue and stack
● Balancing Symbols
● Polynomial representation
Balancing symbols
Algorithm: To check for the balancing of parentheses in a string
procedure BALANCE_ EXPR(E)
/*E is the expression padded with a $ to indicateend of input*/
clear stack;
while not end_of_string(E)
read character; /* read a character from string E*/
if character == '{' //is an open symbol
then push character in to stack;
if character = '}' //is a close symbol
then
if stack is empty then ERROR ()
else {pop the stack;
if character != popped character
then ERROR();
}
endwhile
if stack not empty then ERROR();
end BALANCE_EXPR.
Polynomial representation
COEFF EXP LINK
9 6 3 2 4 0
-2 4
Node structure for polynomial
Linked list representation:
9x6
-2x4
+ 3x2
+ 4.
polynomial
Front reat
Ad

More Related Content

What's hot (20)

Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data Structure
Meghaj Mallick
 
Unit I - Evaluation of expression
Unit I - Evaluation of expressionUnit I - Evaluation of expression
Unit I - Evaluation of expression
DrkhanchanaR
 
SORTING techniques.pptx
SORTING techniques.pptxSORTING techniques.pptx
SORTING techniques.pptx
Dr.Shweta
 
Ppt on Linked list,stack,queue
Ppt on Linked list,stack,queuePpt on Linked list,stack,queue
Ppt on Linked list,stack,queue
Srajan Shukla
 
Computer architecture control unit
Computer architecture control unitComputer architecture control unit
Computer architecture control unit
Mazin Alwaaly
 
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
Afzal Badshah
 
Deque and its applications
Deque and its applicationsDeque and its applications
Deque and its applications
Jsaddam Hussain
 
Queues
QueuesQueues
Queues
Lovely Professional University
 
Stack using Linked List
Stack using Linked ListStack using Linked List
Stack using Linked List
Sayantan Sur
 
Stacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURESStacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURES
Sowmya Jyothi
 
Threaded Binary Tree
Threaded Binary TreeThreaded Binary Tree
Threaded Binary Tree
khabbab_h
 
Red black tree
Red black treeRed black tree
Red black tree
Dr Sandeep Kumar Poonia
 
Merge Sort
Merge SortMerge Sort
Merge Sort
Nikhil Sonkamble
 
358 33 powerpoint-slides_14-sorting_chapter-14
358 33 powerpoint-slides_14-sorting_chapter-14358 33 powerpoint-slides_14-sorting_chapter-14
358 33 powerpoint-slides_14-sorting_chapter-14
sumitbardhan
 
Binary search tree operations
Binary search tree operationsBinary search tree operations
Binary search tree operations
Kamran Zafar
 
Queue
QueueQueue
Queue
Zaid Shabbir
 
Stack and Queue
Stack and Queue Stack and Queue
Stack and Queue
Apurbo Datta
 
Modes Of Transfer in Input/Output Organization
Modes Of Transfer in Input/Output OrganizationModes Of Transfer in Input/Output Organization
Modes Of Transfer in Input/Output Organization
MOHIT AGARWAL
 
Input Output Organization
Input Output OrganizationInput Output Organization
Input Output Organization
Kamal Acharya
 
Queue implementation
Queue implementationQueue implementation
Queue implementation
Rajendran
 
Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data Structure
Meghaj Mallick
 
Unit I - Evaluation of expression
Unit I - Evaluation of expressionUnit I - Evaluation of expression
Unit I - Evaluation of expression
DrkhanchanaR
 
SORTING techniques.pptx
SORTING techniques.pptxSORTING techniques.pptx
SORTING techniques.pptx
Dr.Shweta
 
Ppt on Linked list,stack,queue
Ppt on Linked list,stack,queuePpt on Linked list,stack,queue
Ppt on Linked list,stack,queue
Srajan Shukla
 
Computer architecture control unit
Computer architecture control unitComputer architecture control unit
Computer architecture control unit
Mazin Alwaaly
 
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
Afzal Badshah
 
Deque and its applications
Deque and its applicationsDeque and its applications
Deque and its applications
Jsaddam Hussain
 
Stack using Linked List
Stack using Linked ListStack using Linked List
Stack using Linked List
Sayantan Sur
 
Stacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURESStacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURES
Sowmya Jyothi
 
Threaded Binary Tree
Threaded Binary TreeThreaded Binary Tree
Threaded Binary Tree
khabbab_h
 
358 33 powerpoint-slides_14-sorting_chapter-14
358 33 powerpoint-slides_14-sorting_chapter-14358 33 powerpoint-slides_14-sorting_chapter-14
358 33 powerpoint-slides_14-sorting_chapter-14
sumitbardhan
 
Binary search tree operations
Binary search tree operationsBinary search tree operations
Binary search tree operations
Kamran Zafar
 
Modes Of Transfer in Input/Output Organization
Modes Of Transfer in Input/Output OrganizationModes Of Transfer in Input/Output Organization
Modes Of Transfer in Input/Output Organization
MOHIT AGARWAL
 
Input Output Organization
Input Output OrganizationInput Output Organization
Input Output Organization
Kamal Acharya
 
Queue implementation
Queue implementationQueue implementation
Queue implementation
Rajendran
 

Similar to Linked stack-and-linked-queue (20)

Abscddnddmdkwkkstack implementation.pptx
Abscddnddmdkwkkstack implementation.pptxAbscddnddmdkwkkstack implementation.pptx
Abscddnddmdkwkkstack implementation.pptx
zainshahid3040
 
Bsc cs ii dfs u-2 linklist,stack,queue
Bsc cs ii  dfs u-2 linklist,stack,queueBsc cs ii  dfs u-2 linklist,stack,queue
Bsc cs ii dfs u-2 linklist,stack,queue
Rai University
 
Bca ii dfs u-2 linklist,stack,queue
Bca ii  dfs u-2 linklist,stack,queueBca ii  dfs u-2 linklist,stack,queue
Bca ii dfs u-2 linklist,stack,queue
Rai University
 
Mca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queueMca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queue
Rai University
 
Chapter 5 Stack and Queue.pdf
Chapter 5 Stack and Queue.pdfChapter 5 Stack and Queue.pdf
Chapter 5 Stack and Queue.pdf
GirT2
 
Module 2 ppt.pptx
Module 2 ppt.pptxModule 2 ppt.pptx
Module 2 ppt.pptx
SonaPathak4
 
Queues presentation
Queues presentationQueues presentation
Queues presentation
Toseef Hasan
 
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
RAtna29
 
DS UNIT 2 PPT.pptx stack queue representations
DS UNIT 2 PPT.pptx stack queue representationsDS UNIT 2 PPT.pptx stack queue representations
DS UNIT 2 PPT.pptx stack queue representations
shunmugavadivoot
 
Data structures
Data structuresData structures
Data structures
Sneha Chopra
 
Difference between stack and queue
Difference between stack and queueDifference between stack and queue
Difference between stack and queue
Pulkitmodi1998
 
Stack & Queue in Data Structure and Algorithms
Stack & Queue in Data Structure and AlgorithmsStack & Queue in Data Structure and Algorithms
Stack & Queue in Data Structure and Algorithms
Virgo Lay
 
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
Balwant Gorad
 
Stacks in DATA STRUCTURE
Stacks in DATA STRUCTUREStacks in DATA STRUCTURE
Stacks in DATA STRUCTURE
Mandeep Singh
 
Stacks,queues,linked-list
Stacks,queues,linked-listStacks,queues,linked-list
Stacks,queues,linked-list
pinakspatel
 
Queue
QueueQueue
Queue
Muhammad Farhan
 
Stacks & Queues
Stacks & QueuesStacks & Queues
Stacks & Queues
tech4us
 
Stacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti AroraStacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti Arora
kulachihansraj
 
apllicationsof queffffffffffffffffffffffffffffue.pptx
apllicationsof queffffffffffffffffffffffffffffue.pptxapllicationsof queffffffffffffffffffffffffffffue.pptx
apllicationsof queffffffffffffffffffffffffffffue.pptx
shesnasuneer
 
Stack implementation using linked list ppt
Stack implementation using linked list pptStack implementation using linked list ppt
Stack implementation using linked list ppt
JayasankarShyam
 
Abscddnddmdkwkkstack implementation.pptx
Abscddnddmdkwkkstack implementation.pptxAbscddnddmdkwkkstack implementation.pptx
Abscddnddmdkwkkstack implementation.pptx
zainshahid3040
 
Bsc cs ii dfs u-2 linklist,stack,queue
Bsc cs ii  dfs u-2 linklist,stack,queueBsc cs ii  dfs u-2 linklist,stack,queue
Bsc cs ii dfs u-2 linklist,stack,queue
Rai University
 
Bca ii dfs u-2 linklist,stack,queue
Bca ii  dfs u-2 linklist,stack,queueBca ii  dfs u-2 linklist,stack,queue
Bca ii dfs u-2 linklist,stack,queue
Rai University
 
Mca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queueMca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queue
Rai University
 
Chapter 5 Stack and Queue.pdf
Chapter 5 Stack and Queue.pdfChapter 5 Stack and Queue.pdf
Chapter 5 Stack and Queue.pdf
GirT2
 
Module 2 ppt.pptx
Module 2 ppt.pptxModule 2 ppt.pptx
Module 2 ppt.pptx
SonaPathak4
 
Queues presentation
Queues presentationQueues presentation
Queues presentation
Toseef Hasan
 
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
RAtna29
 
DS UNIT 2 PPT.pptx stack queue representations
DS UNIT 2 PPT.pptx stack queue representationsDS UNIT 2 PPT.pptx stack queue representations
DS UNIT 2 PPT.pptx stack queue representations
shunmugavadivoot
 
Difference between stack and queue
Difference between stack and queueDifference between stack and queue
Difference between stack and queue
Pulkitmodi1998
 
Stack & Queue in Data Structure and Algorithms
Stack & Queue in Data Structure and AlgorithmsStack & Queue in Data Structure and Algorithms
Stack & Queue in Data Structure and Algorithms
Virgo Lay
 
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
Balwant Gorad
 
Stacks in DATA STRUCTURE
Stacks in DATA STRUCTUREStacks in DATA STRUCTURE
Stacks in DATA STRUCTURE
Mandeep Singh
 
Stacks,queues,linked-list
Stacks,queues,linked-listStacks,queues,linked-list
Stacks,queues,linked-list
pinakspatel
 
Stacks & Queues
Stacks & QueuesStacks & Queues
Stacks & Queues
tech4us
 
Stacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti AroraStacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti Arora
kulachihansraj
 
apllicationsof queffffffffffffffffffffffffffffue.pptx
apllicationsof queffffffffffffffffffffffffffffue.pptxapllicationsof queffffffffffffffffffffffffffffue.pptx
apllicationsof queffffffffffffffffffffffffffffue.pptx
shesnasuneer
 
Stack implementation using linked list ppt
Stack implementation using linked list pptStack implementation using linked list ppt
Stack implementation using linked list ppt
JayasankarShyam
 
Ad

More from soniasharmafdp (15)

hashing in data structure for engineering.pptx
hashing in data structure for engineering.pptxhashing in data structure for engineering.pptx
hashing in data structure for engineering.pptx
soniasharmafdp
 
unit 2- linked list- PPT for btech students.pdf
unit 2- linked list- PPT for btech students.pdfunit 2- linked list- PPT for btech students.pdf
unit 2- linked list- PPT for btech students.pdf
soniasharmafdp
 
graphs in data structure for Btech students.pdf
graphs in data structure for Btech students.pdfgraphs in data structure for Btech students.pdf
graphs in data structure for Btech students.pdf
soniasharmafdp
 
New one with new ppt Microsoft Office PowerPoint Presentation.pptx
New one with new ppt Microsoft Office PowerPoint Presentation.pptxNew one with new ppt Microsoft Office PowerPoint Presentation.pptx
New one with new ppt Microsoft Office PowerPoint Presentation.pptx
soniasharmafdp
 
hashing in data structure for Btech .pptx
hashing in data structure for Btech .pptxhashing in data structure for Btech .pptx
hashing in data structure for Btech .pptx
soniasharmafdp
 
classes data type for Btech students.ppt
classes data type for Btech students.pptclasses data type for Btech students.ppt
classes data type for Btech students.ppt
soniasharmafdp
 
hashing in data structure for Btech.pptx
hashing in data structure for Btech.pptxhashing in data structure for Btech.pptx
hashing in data structure for Btech.pptx
soniasharmafdp
 
labwork practice on inhetitance-1.pptx
labwork  practice on  inhetitance-1.pptxlabwork  practice on  inhetitance-1.pptx
labwork practice on inhetitance-1.pptx
soniasharmafdp
 
friend_derivedclasspresentation1234.pptx
friend_derivedclasspresentation1234.pptxfriend_derivedclasspresentation1234.pptx
friend_derivedclasspresentation1234.pptx
soniasharmafdp
 
OOPS PROGRAM for the clarity of functions in c++
OOPS PROGRAM for the clarity of functions in c++OOPS PROGRAM for the clarity of functions in c++
OOPS PROGRAM for the clarity of functions in c++
soniasharmafdp
 
functions in c++ basic concept for students
functions in c++ basic concept for studentsfunctions in c++ basic concept for students
functions in c++ basic concept for students
soniasharmafdp
 
concept of functions and its types in c++ language
concept of functions and its types in c++ languageconcept of functions and its types in c++ language
concept of functions and its types in c++ language
soniasharmafdp
 
Data Bill.pdf
Data Bill.pdfData Bill.pdf
Data Bill.pdf
soniasharmafdp
 
1.3- infix-ti-postfix.pdf
1.3- infix-ti-postfix.pdf1.3- infix-ti-postfix.pdf
1.3- infix-ti-postfix.pdf
soniasharmafdp
 
Datastructureitstypes
DatastructureitstypesDatastructureitstypes
Datastructureitstypes
soniasharmafdp
 
hashing in data structure for engineering.pptx
hashing in data structure for engineering.pptxhashing in data structure for engineering.pptx
hashing in data structure for engineering.pptx
soniasharmafdp
 
unit 2- linked list- PPT for btech students.pdf
unit 2- linked list- PPT for btech students.pdfunit 2- linked list- PPT for btech students.pdf
unit 2- linked list- PPT for btech students.pdf
soniasharmafdp
 
graphs in data structure for Btech students.pdf
graphs in data structure for Btech students.pdfgraphs in data structure for Btech students.pdf
graphs in data structure for Btech students.pdf
soniasharmafdp
 
New one with new ppt Microsoft Office PowerPoint Presentation.pptx
New one with new ppt Microsoft Office PowerPoint Presentation.pptxNew one with new ppt Microsoft Office PowerPoint Presentation.pptx
New one with new ppt Microsoft Office PowerPoint Presentation.pptx
soniasharmafdp
 
hashing in data structure for Btech .pptx
hashing in data structure for Btech .pptxhashing in data structure for Btech .pptx
hashing in data structure for Btech .pptx
soniasharmafdp
 
classes data type for Btech students.ppt
classes data type for Btech students.pptclasses data type for Btech students.ppt
classes data type for Btech students.ppt
soniasharmafdp
 
hashing in data structure for Btech.pptx
hashing in data structure for Btech.pptxhashing in data structure for Btech.pptx
hashing in data structure for Btech.pptx
soniasharmafdp
 
labwork practice on inhetitance-1.pptx
labwork  practice on  inhetitance-1.pptxlabwork  practice on  inhetitance-1.pptx
labwork practice on inhetitance-1.pptx
soniasharmafdp
 
friend_derivedclasspresentation1234.pptx
friend_derivedclasspresentation1234.pptxfriend_derivedclasspresentation1234.pptx
friend_derivedclasspresentation1234.pptx
soniasharmafdp
 
OOPS PROGRAM for the clarity of functions in c++
OOPS PROGRAM for the clarity of functions in c++OOPS PROGRAM for the clarity of functions in c++
OOPS PROGRAM for the clarity of functions in c++
soniasharmafdp
 
functions in c++ basic concept for students
functions in c++ basic concept for studentsfunctions in c++ basic concept for students
functions in c++ basic concept for students
soniasharmafdp
 
concept of functions and its types in c++ language
concept of functions and its types in c++ languageconcept of functions and its types in c++ language
concept of functions and its types in c++ language
soniasharmafdp
 
1.3- infix-ti-postfix.pdf
1.3- infix-ti-postfix.pdf1.3- infix-ti-postfix.pdf
1.3- infix-ti-postfix.pdf
soniasharmafdp
 
Ad

Recently uploaded (20)

IBAAS 2023 Series_Lecture 8- Dr. Nandi.pdf
IBAAS 2023 Series_Lecture 8- Dr. Nandi.pdfIBAAS 2023 Series_Lecture 8- Dr. Nandi.pdf
IBAAS 2023 Series_Lecture 8- Dr. Nandi.pdf
VigneshPalaniappanM
 
ML_Unit_VI_DEEP LEARNING_Introduction to ANN.pdf
ML_Unit_VI_DEEP LEARNING_Introduction to ANN.pdfML_Unit_VI_DEEP LEARNING_Introduction to ANN.pdf
ML_Unit_VI_DEEP LEARNING_Introduction to ANN.pdf
rameshwarchintamani
 
Transport modelling at SBB, presentation at EPFL in 2025
Transport modelling at SBB, presentation at EPFL in 2025Transport modelling at SBB, presentation at EPFL in 2025
Transport modelling at SBB, presentation at EPFL in 2025
Antonin Danalet
 
Personal Protective Efsgfgsffquipment.ppt
Personal Protective Efsgfgsffquipment.pptPersonal Protective Efsgfgsffquipment.ppt
Personal Protective Efsgfgsffquipment.ppt
ganjangbegu579
 
Design Optimization of Reinforced Concrete Waffle Slab Using Genetic Algorithm
Design Optimization of Reinforced Concrete Waffle Slab Using Genetic AlgorithmDesign Optimization of Reinforced Concrete Waffle Slab Using Genetic Algorithm
Design Optimization of Reinforced Concrete Waffle Slab Using Genetic Algorithm
Journal of Soft Computing in Civil Engineering
 
Little Known Ways To 3 Best sites to Buy Linkedin Accounts.pdf
Little Known Ways To 3 Best sites to Buy Linkedin Accounts.pdfLittle Known Ways To 3 Best sites to Buy Linkedin Accounts.pdf
Little Known Ways To 3 Best sites to Buy Linkedin Accounts.pdf
gori42199
 
22PCOAM16 ML Unit 3 Full notes PDF & QB.pdf
22PCOAM16 ML Unit 3 Full notes PDF & QB.pdf22PCOAM16 ML Unit 3 Full notes PDF & QB.pdf
22PCOAM16 ML Unit 3 Full notes PDF & QB.pdf
Guru Nanak Technical Institutions
 
Artificial intelligence and machine learning.pptx
Artificial intelligence and machine learning.pptxArtificial intelligence and machine learning.pptx
Artificial intelligence and machine learning.pptx
rakshanatarajan005
 
Water Industry Process Automation & Control Monthly May 2025
Water Industry Process Automation & Control Monthly May 2025Water Industry Process Automation & Control Monthly May 2025
Water Industry Process Automation & Control Monthly May 2025
Water Industry Process Automation & Control
 
Citizen Observatories to encourage more democratic data evidence-based decisi...
Citizen Observatories to encourage more democratic data evidence-based decisi...Citizen Observatories to encourage more democratic data evidence-based decisi...
Citizen Observatories to encourage more democratic data evidence-based decisi...
Diego López-de-Ipiña González-de-Artaza
 
Smart City is the Future EN - 2024 Thailand Modify V1.0.pdf
Smart City is the Future EN - 2024 Thailand Modify V1.0.pdfSmart City is the Future EN - 2024 Thailand Modify V1.0.pdf
Smart City is the Future EN - 2024 Thailand Modify V1.0.pdf
PawachMetharattanara
 
01.คุณลักษณะเฉพาะของอุปกรณ์_pagenumber.pdf
01.คุณลักษณะเฉพาะของอุปกรณ์_pagenumber.pdf01.คุณลักษณะเฉพาะของอุปกรณ์_pagenumber.pdf
01.คุณลักษณะเฉพาะของอุปกรณ์_pagenumber.pdf
PawachMetharattanara
 
vtc2018fall_otfs_tutorial_presentation_1.pdf
vtc2018fall_otfs_tutorial_presentation_1.pdfvtc2018fall_otfs_tutorial_presentation_1.pdf
vtc2018fall_otfs_tutorial_presentation_1.pdf
RaghavaGD1
 
twin tower attack 2001 new york city
twin  tower  attack  2001 new  york citytwin  tower  attack  2001 new  york city
twin tower attack 2001 new york city
harishreemavs
 
Jacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia - Excels In Optimizing Software ApplicationsJacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia
 
David Boutry - Specializes In AWS, Microservices And Python.pdf
David Boutry - Specializes In AWS, Microservices And Python.pdfDavid Boutry - Specializes In AWS, Microservices And Python.pdf
David Boutry - Specializes In AWS, Microservices And Python.pdf
David Boutry
 
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
ajayrm685
 
Agents chapter of Artificial intelligence
Agents chapter of Artificial intelligenceAgents chapter of Artificial intelligence
Agents chapter of Artificial intelligence
DebdeepMukherjee9
 
ATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ATAL 6 Days Online FDP Scheme Document 2025-26.pdfATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ssuserda39791
 
Using the Artificial Neural Network to Predict the Axial Strength and Strain ...
Using the Artificial Neural Network to Predict the Axial Strength and Strain ...Using the Artificial Neural Network to Predict the Axial Strength and Strain ...
Using the Artificial Neural Network to Predict the Axial Strength and Strain ...
Journal of Soft Computing in Civil Engineering
 
IBAAS 2023 Series_Lecture 8- Dr. Nandi.pdf
IBAAS 2023 Series_Lecture 8- Dr. Nandi.pdfIBAAS 2023 Series_Lecture 8- Dr. Nandi.pdf
IBAAS 2023 Series_Lecture 8- Dr. Nandi.pdf
VigneshPalaniappanM
 
ML_Unit_VI_DEEP LEARNING_Introduction to ANN.pdf
ML_Unit_VI_DEEP LEARNING_Introduction to ANN.pdfML_Unit_VI_DEEP LEARNING_Introduction to ANN.pdf
ML_Unit_VI_DEEP LEARNING_Introduction to ANN.pdf
rameshwarchintamani
 
Transport modelling at SBB, presentation at EPFL in 2025
Transport modelling at SBB, presentation at EPFL in 2025Transport modelling at SBB, presentation at EPFL in 2025
Transport modelling at SBB, presentation at EPFL in 2025
Antonin Danalet
 
Personal Protective Efsgfgsffquipment.ppt
Personal Protective Efsgfgsffquipment.pptPersonal Protective Efsgfgsffquipment.ppt
Personal Protective Efsgfgsffquipment.ppt
ganjangbegu579
 
Little Known Ways To 3 Best sites to Buy Linkedin Accounts.pdf
Little Known Ways To 3 Best sites to Buy Linkedin Accounts.pdfLittle Known Ways To 3 Best sites to Buy Linkedin Accounts.pdf
Little Known Ways To 3 Best sites to Buy Linkedin Accounts.pdf
gori42199
 
Artificial intelligence and machine learning.pptx
Artificial intelligence and machine learning.pptxArtificial intelligence and machine learning.pptx
Artificial intelligence and machine learning.pptx
rakshanatarajan005
 
Citizen Observatories to encourage more democratic data evidence-based decisi...
Citizen Observatories to encourage more democratic data evidence-based decisi...Citizen Observatories to encourage more democratic data evidence-based decisi...
Citizen Observatories to encourage more democratic data evidence-based decisi...
Diego López-de-Ipiña González-de-Artaza
 
Smart City is the Future EN - 2024 Thailand Modify V1.0.pdf
Smart City is the Future EN - 2024 Thailand Modify V1.0.pdfSmart City is the Future EN - 2024 Thailand Modify V1.0.pdf
Smart City is the Future EN - 2024 Thailand Modify V1.0.pdf
PawachMetharattanara
 
01.คุณลักษณะเฉพาะของอุปกรณ์_pagenumber.pdf
01.คุณลักษณะเฉพาะของอุปกรณ์_pagenumber.pdf01.คุณลักษณะเฉพาะของอุปกรณ์_pagenumber.pdf
01.คุณลักษณะเฉพาะของอุปกรณ์_pagenumber.pdf
PawachMetharattanara
 
vtc2018fall_otfs_tutorial_presentation_1.pdf
vtc2018fall_otfs_tutorial_presentation_1.pdfvtc2018fall_otfs_tutorial_presentation_1.pdf
vtc2018fall_otfs_tutorial_presentation_1.pdf
RaghavaGD1
 
twin tower attack 2001 new york city
twin  tower  attack  2001 new  york citytwin  tower  attack  2001 new  york city
twin tower attack 2001 new york city
harishreemavs
 
Jacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia - Excels In Optimizing Software ApplicationsJacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia
 
David Boutry - Specializes In AWS, Microservices And Python.pdf
David Boutry - Specializes In AWS, Microservices And Python.pdfDavid Boutry - Specializes In AWS, Microservices And Python.pdf
David Boutry - Specializes In AWS, Microservices And Python.pdf
David Boutry
 
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
ajayrm685
 
Agents chapter of Artificial intelligence
Agents chapter of Artificial intelligenceAgents chapter of Artificial intelligence
Agents chapter of Artificial intelligence
DebdeepMukherjee9
 
ATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ATAL 6 Days Online FDP Scheme Document 2025-26.pdfATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ATAL 6 Days Online FDP Scheme Document 2025-26.pdf
ssuserda39791
 

Linked stack-and-linked-queue

  • 1. Linked Stack and Linked Queue Chapter 7
  • 2. Outline ● Introduction – Linked Stacks – Linked Queues ● Operations on Linked Stacks and Linked Queues – Linked Stack Operations – Linked Queue Operations – Algorithms for Push/Pop operations on a Linked Stack – Algorithms for Insert/Delete operations in a Linked Queue ● Dynamic memory management and Linked Stacks ● Implementation of Linked Representations ● Applications – Balancing Symbols – Polynomial Representation
  • 3. Introduction ● A linked stack is a linear list of elements commonly implemented as a singly linked list whose start pointer performs the role of the top pointer of a stack ● A linked queue is also a linear list of elements commonly implemented as a singly linked list but with two pointers viz., FRONT and REAR. The start pointer of the singly linked list plays the role of FRONT while the pointer to the last node is set to play the role of REAR.
  • 4. Implementing Stack and Queue Using Linked List 6 1 2 3 4 5 A B E D G F Top = 6 1 2 3 4 5 6 B C Front=1 Rear = 3 Stack[1:6] Queue[1:6] B C G H stack Top B C G H queue front rear
  • 5. Operations of Linked Stack and Linked Queue
  • 6. Operations on Linked Stack ● Push – GETNODE(X) – LINK(X) = Top – Top = X B C G H stack Top C X
  • 7. Algorithm: Push item ITEM into a linked stack S with top pointer TOP procedure PUSH_LINKSTACK (TOP, ITEM) /* Insert ITEM into stack */ Call GETNODE(X) DATA(X) = ITEM /*frame node for ITEM */ LINK(X) = TOP /* insert node X into stack */ TOP = X /* reset TOP pointer */ end PUSH_LINKSTACK.
  • 8. ● Pop – Temp = Top – Item = DATA(Top) – Top = LINK(TOP) – RETURN(Temp) B C G H stack Top Temp
  • 9. Algorithm: Pop from a linked stack S and output the element through ITEM procedure POP_LINKSTACK(TOP, ITEM) /* pop element from stack and set ITEM to the element */ if (TOP = 0) then call LINKSTACK_EMPTY /* check if linked stack is empty */ else { TEMP = TOP ITEM = DATA(TOP) TOP = LINK(TOP) } call RETURN(TEMP) ; end POP_LINKSTACK.
  • 10. ● Enqueue – LINK(rear) = X – Rear = X B C G H queue front rear A X B C G H queue front rear
  • 11. Algorithm: Enqueue an ITEM into a linked list queue Q procedure INSERT_LINKQUEUE(FRONT,REAR,ITEM) Call GETNODE(X); DATA(X)= ITEM; LINK(X)= NIL; /* Node with ITEM is ready to be inserted into Q */ if (Queue = 0) then •Queue = FRONT = REAR = X; /* If Q is empty then ITEM is the first element in the queue Q else {LINK(REAR) = X; REAR = X } end INSERT_LINKQUEUE.
  • 12. ● Dequeue – Temp = front – front = Link(front) – Item = DATA(Temp) – RETURN(Temp) B C G H queue front rear Temp
  • 13. Algorithm: Dequeue an element from the linked queue Q procedure DELETE_LINKQUEUE (FRONT,ITEM) if (FRONT = 0) then call LINKQUEUE_EMPTY; /* Test condition to avoid deletion in an empty queue */ else {TEMP = FRONT; ITEM = DATA (TEMP); FRONT = LINK (TEMP); } call RETURN (TEMP); /* return the node TEMP to the free pool */ end DELETE_LINKQUEUE.
  • 14. Implementing Linked list Queue and stack ● Balancing Symbols ● Polynomial representation
  • 15. Balancing symbols Algorithm: To check for the balancing of parentheses in a string procedure BALANCE_ EXPR(E) /*E is the expression padded with a $ to indicateend of input*/ clear stack; while not end_of_string(E) read character; /* read a character from string E*/ if character == '{' //is an open symbol then push character in to stack; if character = '}' //is a close symbol then if stack is empty then ERROR () else {pop the stack; if character != popped character then ERROR(); } endwhile if stack not empty then ERROR(); end BALANCE_EXPR.
  • 16. Polynomial representation COEFF EXP LINK 9 6 3 2 4 0 -2 4 Node structure for polynomial Linked list representation: 9x6 -2x4 + 3x2 + 4. polynomial Front reat
  翻译: