SlideShare a Scribd company logo
1 of 12
Presented BY : Shraddha Malviya
“Stack and Queue using Linked List”
Roll No. : MCA/25018/18
Stack
A stack is an ordered list with the restriction that element are
added or deleted from only one end of list termed top of stack. The
other end of the list which lies ‘inactive’ is termed bottom of stack.
Stack using linked list
A linked stack is a linear list of elements commonly
implemented as a singly linked list whose start
pointer perform the role of the top pointer of stack .
c b a
top
Linked representation of stack
Stack operation :
Push operation-
c a
top
b
Linked stack S
Push ‘d’ into S
cd ab
top
top
Push operation
PUSH_LINKSTACK(TOP,ITEM)
Call GETNODE(X)
DATA(X) = ITEM /*frame node item */
LINK(X) = TOP /* insert into x into stack */
TOP = X /*reset Top pointer */
end PUSH_LINKSTACK.
Pop operation-
c ab
Linked stack Stop
Pop ‘c’ from S
c ab
top
top
Push operation
POP_LINKSTACK(TOP,ITEM)
if(TOP=0)
then call LINKSTACK_EMPTY
else
{
TEMP=TOP;
ITEM=DATA(TOP);
TOP=LINK(TOP);
}
Call RETURN (TEMP)
end POP_LINKSTACK
Queue
A Queue is a linear list in which all insertion are
made at one end of the list known as rear or tail of
queue and all deletion are made at the other end
known as front or head of the queue . An insertion
operation is also referred to as enqueuing a queue
and deletion operation is referred to as dequeuing a
queue.
Queue using linked list
A linked queue is also linear list of element
commonly implemented as a singly linked list but
with two pointer ,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 .
a b c
front
rear
Linked representation of queue
Queue operation :
Insert operation--
a b
front
c
rear
Insert ‘d into queue’
a b dc
rear
front
rear
Insertion operation
INSERT_LINKQUEUE(FRONT,REAR,
ITEM)
Call GETNODE (X);
DATA (X) = ITEM;
LINK (X) = NIL;
if(FRONT = 0)
then FRONT = REAR = X;
else
{
LINK (REAR) = X;
REAR = X;
}
end INSERT_LINKQUEUE
Delete operation--
a b c
rear
front
Delete ‘a’ from queue
front
a b c
rear
front
Delete operation
DELETE_LINKQUEUE (FRONT , ITEM)
if(FRONT = 0)
then call LINKQUEUE_EMPTY;
else
{
TEMP = FRONT;
ITEM= DATA(TEMP);
FRONT = LINK(TEMP);
}
call RETURN (TEMP);
end DELETE_LINKQUEUE
Application
 Balancing symbol
Reference:
DATA STRUCTURES AND ALGORITHMS, GAV
Book:
THANKYOU

More Related Content

What's hot

Stacks Implementation and Examples
Stacks Implementation and ExamplesStacks Implementation and Examples
Stacks Implementation and Examples
greatqadirgee4u
 

What's hot (20)

Queue data structure
Queue data structureQueue data structure
Queue data structure
 
Graph traversals in Data Structures
Graph traversals in Data StructuresGraph traversals in Data Structures
Graph traversals in Data Structures
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
 
Stack using Linked List
Stack using Linked ListStack using Linked List
Stack using Linked List
 
Binary search tree(bst)
Binary search tree(bst)Binary search tree(bst)
Binary search tree(bst)
 
Polynomial reppresentation using Linkedlist-Application of LL.pptx
Polynomial reppresentation using Linkedlist-Application of LL.pptxPolynomial reppresentation using Linkedlist-Application of LL.pptx
Polynomial reppresentation using Linkedlist-Application of LL.pptx
 
sparse matrix in data structure
sparse matrix in data structuresparse matrix in data structure
sparse matrix in data structure
 
Applications of stack
Applications of stackApplications of stack
Applications of stack
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure
 
UNIT I LINEAR DATA STRUCTURES – LIST
UNIT I 	LINEAR DATA STRUCTURES – LIST 	UNIT I 	LINEAR DATA STRUCTURES – LIST
UNIT I LINEAR DATA STRUCTURES – LIST
 
stack presentation
stack presentationstack presentation
stack presentation
 
Data structure using c module 1
Data structure using c module 1Data structure using c module 1
Data structure using c module 1
 
DFS and BFS
DFS and BFSDFS and BFS
DFS and BFS
 
Searching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And AlgorithmSearching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And Algorithm
 
Insertion in singly linked list
Insertion in singly linked listInsertion in singly linked list
Insertion in singly linked list
 
Queues
QueuesQueues
Queues
 
Stacks Implementation and Examples
Stacks Implementation and ExamplesStacks Implementation and Examples
Stacks Implementation and Examples
 
Linked list implementation of Queue
Linked list implementation of QueueLinked list implementation of Queue
Linked list implementation of Queue
 
Data Structure and Algorithms Linked List
Data Structure and Algorithms Linked ListData Structure and Algorithms Linked List
Data Structure and Algorithms Linked List
 
Binary Heap Tree, Data Structure
Binary Heap Tree, Data Structure Binary Heap Tree, Data Structure
Binary Heap Tree, Data Structure
 

Similar to Stack & Queue using Linked List in Data Structure

Stacks & Queues
Stacks & QueuesStacks & Queues
Stacks & Queues
tech4us
 
C++ Program It is only 1 rotation. Up-rotation of a stack. Write a.pdf
C++ Program It is only 1 rotation. Up-rotation of a stack.  Write a.pdfC++ Program It is only 1 rotation. Up-rotation of a stack.  Write a.pdf
C++ Program It is only 1 rotation. Up-rotation of a stack. Write a.pdf
pallavi953613
 
Lec5-Stack-bukc-28022024-112316am (1) .pptx
Lec5-Stack-bukc-28022024-112316am (1) .pptxLec5-Stack-bukc-28022024-112316am (1) .pptx
Lec5-Stack-bukc-28022024-112316am (1) .pptx
haaamin01
 

Similar to Stack & Queue using Linked List in Data Structure (20)

Stacks in c++
Stacks in c++Stacks in c++
Stacks in c++
 
Queues presentation
Queues presentationQueues presentation
Queues presentation
 
stacks and queues
stacks and queuesstacks and queues
stacks and queues
 
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
 
Linked stack-and-linked-queue
Linked stack-and-linked-queueLinked stack-and-linked-queue
Linked stack-and-linked-queue
 
Stack and Queue
Stack and Queue Stack and Queue
Stack and Queue
 
Stacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti AroraStacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti Arora
 
Stacks & Queues
Stacks & QueuesStacks & Queues
Stacks & Queues
 
Data structures1
Data structures1Data structures1
Data structures1
 
Queue
QueueQueue
Queue
 
C++ Program It is only 1 rotation. Up-rotation of a stack. Write a.pdf
C++ Program It is only 1 rotation. Up-rotation of a stack.  Write a.pdfC++ Program It is only 1 rotation. Up-rotation of a stack.  Write a.pdf
C++ Program It is only 1 rotation. Up-rotation of a stack. Write a.pdf
 
Stack push pop
Stack push popStack push pop
Stack push pop
 
Stack data structure
Stack data structureStack data structure
Stack data structure
 
Data structures stacks
Data structures   stacksData structures   stacks
Data structures stacks
 
Queues and Stacks
Queues and StacksQueues and Stacks
Queues and Stacks
 
Stacks,queues,linked-list
Stacks,queues,linked-listStacks,queues,linked-list
Stacks,queues,linked-list
 
Lec5-Stack-bukc-28022024-112316am (1) .pptx
Lec5-Stack-bukc-28022024-112316am (1) .pptxLec5-Stack-bukc-28022024-112316am (1) .pptx
Lec5-Stack-bukc-28022024-112316am (1) .pptx
 
Stack queue
Stack queueStack queue
Stack queue
 
Stack queue
Stack queueStack queue
Stack queue
 
Stack queue
Stack queueStack queue
Stack queue
 

More from Meghaj Mallick

More from Meghaj Mallick (20)

24 partial-orderings
24 partial-orderings24 partial-orderings
24 partial-orderings
 
PORTFOLIO BY USING HTML & CSS
PORTFOLIO BY USING HTML & CSSPORTFOLIO BY USING HTML & CSS
PORTFOLIO BY USING HTML & CSS
 
Introduction to Software Testing
Introduction to Software TestingIntroduction to Software Testing
Introduction to Software Testing
 
Introduction to System Programming
Introduction to System ProgrammingIntroduction to System Programming
Introduction to System Programming
 
MACRO ASSEBLER
MACRO ASSEBLERMACRO ASSEBLER
MACRO ASSEBLER
 
Icons, Image & Multimedia
Icons, Image & MultimediaIcons, Image & Multimedia
Icons, Image & Multimedia
 
Project Tracking & SPC
Project Tracking & SPCProject Tracking & SPC
Project Tracking & SPC
 
Peephole Optimization
Peephole OptimizationPeephole Optimization
Peephole Optimization
 
Routing in MANET
Routing in MANETRouting in MANET
Routing in MANET
 
Macro assembler
 Macro assembler Macro assembler
Macro assembler
 
Architecture and security in Vanet PPT
Architecture and security in Vanet PPTArchitecture and security in Vanet PPT
Architecture and security in Vanet PPT
 
Design Model & User Interface Design in Software Engineering
Design Model & User Interface Design in Software EngineeringDesign Model & User Interface Design in Software Engineering
Design Model & User Interface Design in Software Engineering
 
Text Mining of Twitter in Data Mining
Text Mining of Twitter in Data MiningText Mining of Twitter in Data Mining
Text Mining of Twitter in Data Mining
 
DFS & BFS in Computer Algorithm
DFS & BFS in Computer AlgorithmDFS & BFS in Computer Algorithm
DFS & BFS in Computer Algorithm
 
Software Development Method
Software Development MethodSoftware Development Method
Software Development Method
 
Secant method in Numerical & Statistical Method
Secant method in Numerical & Statistical MethodSecant method in Numerical & Statistical Method
Secant method in Numerical & Statistical Method
 
Motivation in Organization
Motivation in OrganizationMotivation in Organization
Motivation in Organization
 
Communication Skill
Communication SkillCommunication Skill
Communication Skill
 
Partial-Orderings in Discrete Mathematics
 Partial-Orderings in Discrete Mathematics Partial-Orderings in Discrete Mathematics
Partial-Orderings in Discrete Mathematics
 
Hashing In Data Structure
Hashing In Data Structure Hashing In Data Structure
Hashing In Data Structure
 

Recently uploaded

Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...
Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...
Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...
ZurliaSoop
 
Unlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven Curiosity
Unlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven CuriosityUnlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven Curiosity
Unlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven Curiosity
Hung Le
 
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
David Celestin
 

Recently uploaded (19)

History of Morena Moshoeshoe birth death
History of Morena Moshoeshoe birth deathHistory of Morena Moshoeshoe birth death
History of Morena Moshoeshoe birth death
 
The Concession of Asaba International Airport: Balancing Politics and Policy ...
The Concession of Asaba International Airport: Balancing Politics and Policy ...The Concession of Asaba International Airport: Balancing Politics and Policy ...
The Concession of Asaba International Airport: Balancing Politics and Policy ...
 
Abortion Pills Fahaheel ௹+918133066128💬@ Safe and Effective Mifepristion and ...
Abortion Pills Fahaheel ௹+918133066128💬@ Safe and Effective Mifepristion and ...Abortion Pills Fahaheel ௹+918133066128💬@ Safe and Effective Mifepristion and ...
Abortion Pills Fahaheel ௹+918133066128💬@ Safe and Effective Mifepristion and ...
 
Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...
Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...
Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...
 
LITTLE ABOUT LESOTHO FROM THE TIME MOSHOESHOE THE FIRST WAS BORN
LITTLE ABOUT LESOTHO FROM THE TIME MOSHOESHOE THE FIRST WAS BORNLITTLE ABOUT LESOTHO FROM THE TIME MOSHOESHOE THE FIRST WAS BORN
LITTLE ABOUT LESOTHO FROM THE TIME MOSHOESHOE THE FIRST WAS BORN
 
2024 mega trends for the digital workplace - FINAL.pdf
2024 mega trends for the digital workplace - FINAL.pdf2024 mega trends for the digital workplace - FINAL.pdf
2024 mega trends for the digital workplace - FINAL.pdf
 
Introduction to Artificial intelligence.
Introduction to Artificial intelligence.Introduction to Artificial intelligence.
Introduction to Artificial intelligence.
 
Unlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven Curiosity
Unlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven CuriosityUnlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven Curiosity
Unlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven Curiosity
 
Using AI to boost productivity for developers
Using AI to boost productivity for developersUsing AI to boost productivity for developers
Using AI to boost productivity for developers
 
ICT role in 21st century education and it's challenges.pdf
ICT role in 21st century education and it's challenges.pdfICT role in 21st century education and it's challenges.pdf
ICT role in 21st century education and it's challenges.pdf
 
"I hear you": Moving beyond empathy in UXR
"I hear you": Moving beyond empathy in UXR"I hear you": Moving beyond empathy in UXR
"I hear you": Moving beyond empathy in UXR
 
Ready Set Go Children Sermon about Mark 16:15-20
Ready Set Go Children Sermon about Mark 16:15-20Ready Set Go Children Sermon about Mark 16:15-20
Ready Set Go Children Sermon about Mark 16:15-20
 
BIG DEVELOPMENTS IN LESOTHO(DAMS & MINES
BIG DEVELOPMENTS IN LESOTHO(DAMS & MINESBIG DEVELOPMENTS IN LESOTHO(DAMS & MINES
BIG DEVELOPMENTS IN LESOTHO(DAMS & MINES
 
ECOLOGY OF FISHES.pptx full presentation
ECOLOGY OF FISHES.pptx full presentationECOLOGY OF FISHES.pptx full presentation
ECOLOGY OF FISHES.pptx full presentation
 
SOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdf
SOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdfSOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdf
SOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdf
 
BEAUTIFUL PLACES TO VISIT IN LESOTHO.pptx
BEAUTIFUL PLACES TO VISIT IN LESOTHO.pptxBEAUTIFUL PLACES TO VISIT IN LESOTHO.pptx
BEAUTIFUL PLACES TO VISIT IN LESOTHO.pptx
 
Digital collaboration with Microsoft 365 as extension of Drupal
Digital collaboration with Microsoft 365 as extension of DrupalDigital collaboration with Microsoft 365 as extension of Drupal
Digital collaboration with Microsoft 365 as extension of Drupal
 
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
 
in kuwait௹+918133066128....) @abortion pills for sale in Kuwait City
in kuwait௹+918133066128....) @abortion pills for sale in Kuwait Cityin kuwait௹+918133066128....) @abortion pills for sale in Kuwait City
in kuwait௹+918133066128....) @abortion pills for sale in Kuwait City
 

Stack & Queue using Linked List in Data Structure

  • 1. Presented BY : Shraddha Malviya “Stack and Queue using Linked List” Roll No. : MCA/25018/18
  • 2. Stack A stack is an ordered list with the restriction that element are added or deleted from only one end of list termed top of stack. The other end of the list which lies ‘inactive’ is termed bottom of stack.
  • 3. Stack using linked list A linked stack is a linear list of elements commonly implemented as a singly linked list whose start pointer perform the role of the top pointer of stack . c b a top Linked representation of stack
  • 4. Stack operation : Push operation- c a top b Linked stack S Push ‘d’ into S cd ab top top Push operation PUSH_LINKSTACK(TOP,ITEM) Call GETNODE(X) DATA(X) = ITEM /*frame node item */ LINK(X) = TOP /* insert into x into stack */ TOP = X /*reset Top pointer */ end PUSH_LINKSTACK.
  • 5. Pop operation- c ab Linked stack Stop Pop ‘c’ from S c ab top top Push operation POP_LINKSTACK(TOP,ITEM) if(TOP=0) then call LINKSTACK_EMPTY else { TEMP=TOP; ITEM=DATA(TOP); TOP=LINK(TOP); } Call RETURN (TEMP) end POP_LINKSTACK
  • 6. Queue A Queue is a linear list in which all insertion are made at one end of the list known as rear or tail of queue and all deletion are made at the other end known as front or head of the queue . An insertion operation is also referred to as enqueuing a queue and deletion operation is referred to as dequeuing a queue.
  • 7. Queue using linked list A linked queue is also linear list of element commonly implemented as a singly linked list but with two pointer ,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 . a b c front rear Linked representation of queue
  • 8. Queue operation : Insert operation-- a b front c rear Insert ‘d into queue’ a b dc rear front rear Insertion operation INSERT_LINKQUEUE(FRONT,REAR, ITEM) Call GETNODE (X); DATA (X) = ITEM; LINK (X) = NIL; if(FRONT = 0) then FRONT = REAR = X; else { LINK (REAR) = X; REAR = X; } end INSERT_LINKQUEUE
  • 9. Delete operation-- a b c rear front Delete ‘a’ from queue front a b c rear front Delete operation DELETE_LINKQUEUE (FRONT , ITEM) if(FRONT = 0) then call LINKQUEUE_EMPTY; else { TEMP = FRONT; ITEM= DATA(TEMP); FRONT = LINK(TEMP); } call RETURN (TEMP); end DELETE_LINKQUEUE
  • 11. Reference: DATA STRUCTURES AND ALGORITHMS, GAV Book: