SlideShare a Scribd company logo
DATA STRUCTURE
STACKS AND QUEUES
Prepared by : SELVIN JOSY BAI.S
STACK
 It is a linear data structure in which an elements
may be inserted or deleted only at one end called the
top of the stack.
 This data structure implemented in LIFO (Last In
First Out) manner
 LIFO means element last inserted would be the first
one to be deleted.
 The Stack is also a dynamic data structure as it
can grow or shrink.
 Real life example :
 A stack OF DISCS IN HOLDER
 A stack of TOKENS IN HOLDER
 Two basic operations of stack
 PUSHING : An Insertion in a stack is called
PUSHING.
 POPPING : A Deletion from a stack is called
POPPING.
PUSHING ALGORITHM
1. Read ITEM
2. If TOP = N then Print “OVERFLOW”
and Stop
3. Else set TOP = TOP + 1
//Creating a space for a new element
4. Set STACK [ TOP ] = ITEM
//Inserting the new ITEM
5. Stop
1 2 3 4 5
TOP
N 5
NULL
POPPING ALGORITHM
1. If TOP = NULL then
Print “UNDERFLOW” and return
2. Else set ITEM =STACK [ TOP ]
3. Set TOP = TOP - 1
4. Stop
1 2 3 4 5
TOP
APPLICATIONS OF STACK
 TO REVERSING A STRING
 TO EVALUATE NOTATIONAL
EXPRESSION(INFIX, PREFIX, & POSTFIX)
 TO CONVERT FROM ONE EXPRESSION TO
ANOTHER.
QUEUE
 It is a linear data structure in which an element may
be inserted only at one end, called the REAR end and
deletions can be take place at the other end, called the
FRONT end.
 This data structure implemented in FIFO (First In
First Out) manner
 FIFO means element first inserted would be the first
one to be deleted.
 The Queue is also a dynamic data structure as it can
grow or shrink.
 However, if additions and deletions are made at both
ends of a queue, then such a queue is called Double
Ended Queue or simply DEQUE.
The following operations can be performed
on Queues
1. Addition of an element at the REAR end of the
queue
2. Deletion of an element from the FRONT end of
the queue
Real life example :
• People waiting at a railway station counter for
taking tickets
Algorithm for INSERTION
1. If FRONT = 1 and REAR = N or
If FRONT = REAR + 1 then
Print “OVERFLOW” ; stop
2. if FRONT = NULL then
set FRONT = 1 and REAR = 1
3. Else if REAR = N then
set REAR = 1
4. Else set REAR = REAR + 1
5. Endif
6. Set QUEUE [ REAR ] = ITEM
7. Stop
Algorithm for DELETION
1. If FRONT = NULL then
Print “UNDERFLOW” ; stop
2. set ITEM = QUEUE [FRONT]
3. If FRONT = REAR then
set FRONT = NULL and REAR = NULL
4. Else if FRONT = N then set FRONT = 1
5. Else set FRONT = FRONT + 1
6. Stop
APPLICATIONS OF QUEUE
 IT OCCURS IN THE JOB SCHEDULING
 THE COMPUTER OS USE THIS CONCEPT
IN SCHEDULING THE MEMORY,
PROCESSOR AND THE FILES.
 USED FOR SCHEDULING JOBS AND
SERVICES.
EXERCISE - 1
 In CD pack, the CDs are placed one over the
other through a central axis. Assume that there
are 25 CDs in the pack.
a. Name the data structure that resembles with the
CD pack.
b. Considering the CD pack as an array in C++, how
will you name the position of the last CD and what
will be its value?
c. Write an algorithm to remove a CD from the pack
and name the operation performed.
EXERCISE - 2
 While waiting for a ticket at the railway station
ticket counter, you are following the principle
as that of a data structure
a. Name the data structure and the principle
b. Write a C++ function to add a new element in this
data structure.
c. Name the situation where there is no space for
adding new element
Some more Questions
1. What is overflow and underflow?
2. Explain the terms PUSH and POP?
3. What are the applications of stacks and
queues?
4. Name the data structure that resembles a
person placing plates in a vessel. Write
an algorithm for inserting a plate.

More Related Content

What's hot (20)

Stack
StackStack
Stack
 
Stack
StackStack
Stack
 
Queue
QueueQueue
Queue
 
Stack a Data Structure
Stack a Data StructureStack a Data Structure
Stack a Data Structure
 
Circular queue
Circular queueCircular queue
Circular queue
 
Queues
QueuesQueues
Queues
 
Stack and Queue
Stack and Queue Stack and Queue
Stack and Queue
 
stack & queue
stack & queuestack & queue
stack & queue
 
Data structure by Digvijay
Data structure by DigvijayData structure by Digvijay
Data structure by Digvijay
 
STACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data StructureSTACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data Structure
 
Stack - Data Structure
Stack - Data StructureStack - Data Structure
Stack - Data Structure
 
Stacks overview with its applications
Stacks overview with its applicationsStacks overview with its applications
Stacks overview with its applications
 
My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular queue
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applications
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 Data Structures - Lecture 9 [Stack & Queue using Linked List] Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 
Stacks and Queue - Data Structures
Stacks and Queue - Data StructuresStacks and Queue - Data Structures
Stacks and Queue - Data Structures
 
Data structure Stack
Data structure StackData structure Stack
Data structure Stack
 
Queues
QueuesQueues
Queues
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
 
Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data Structure
 

Viewers also liked

Queue and stacks
Queue and stacksQueue and stacks
Queue and stacksgrahamwell
 
TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....
TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....
TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....Shail Nakum
 
Ppt presentation of queues
Ppt presentation of queuesPpt presentation of queues
Ppt presentation of queuesBuxoo Abdullah
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data StructureZidny Nafan
 
Presentation on half and full wave ractifier.ppt
Presentation on half and full wave ractifier.pptPresentation on half and full wave ractifier.ppt
Presentation on half and full wave ractifier.pptKawsar Ahmed
 
Notes DATA STRUCTURE - queue
Notes DATA STRUCTURE - queueNotes DATA STRUCTURE - queue
Notes DATA STRUCTURE - queueFarhanum Aziera
 
DATA STRUCTURES
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURESbca2010
 

Viewers also liked (8)

Queue
QueueQueue
Queue
 
Queue and stacks
Queue and stacksQueue and stacks
Queue and stacks
 
TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....
TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....
TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....
 
Ppt presentation of queues
Ppt presentation of queuesPpt presentation of queues
Ppt presentation of queues
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Presentation on half and full wave ractifier.ppt
Presentation on half and full wave ractifier.pptPresentation on half and full wave ractifier.ppt
Presentation on half and full wave ractifier.ppt
 
Notes DATA STRUCTURE - queue
Notes DATA STRUCTURE - queueNotes DATA STRUCTURE - queue
Notes DATA STRUCTURE - queue
 
DATA STRUCTURES
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURES
 

Similar to Data structure stack&queue basics

Difference between stack and queue
Difference between stack and queueDifference between stack and queue
Difference between stack and queuePulkitmodi1998
 
Stacks queues-1220971554378778-9
Stacks queues-1220971554378778-9Stacks queues-1220971554378778-9
Stacks queues-1220971554378778-9Getachew Ganfur
 
Stacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti AroraStacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti Arorakulachihansraj
 
Stacks & Queues
Stacks & QueuesStacks & Queues
Stacks & Queuestech4us
 
Data Structures by Maneesh Boddu
Data Structures by Maneesh BodduData Structures by Maneesh Boddu
Data Structures by Maneesh Boddumaneesh boddu
 
Stacks,queues,linked-list
Stacks,queues,linked-listStacks,queues,linked-list
Stacks,queues,linked-listpinakspatel
 
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 operationspoongothai11
 
Stacks Data structure.pptx
Stacks Data structure.pptxStacks Data structure.pptx
Stacks Data structure.pptxline24arts
 
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
 
Data structure lecture7
Data structure lecture7Data structure lecture7
Data structure lecture7Kumar
 

Similar to Data structure stack&queue basics (20)

Difference between stack and queue
Difference between stack and queueDifference between stack and queue
Difference between stack and queue
 
Rana Junaid Rasheed
Rana Junaid RasheedRana Junaid Rasheed
Rana Junaid Rasheed
 
Stacks queues-1220971554378778-9
Stacks queues-1220971554378778-9Stacks queues-1220971554378778-9
Stacks queues-1220971554378778-9
 
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
 
Stacks in c++
Stacks in c++Stacks in c++
Stacks in c++
 
Stack.pptx
Stack.pptxStack.pptx
Stack.pptx
 
04 stacks
04 stacks04 stacks
04 stacks
 
Data Structures by Maneesh Boddu
Data Structures by Maneesh BodduData Structures by Maneesh Boddu
Data Structures by Maneesh Boddu
 
Stacks,queues,linked-list
Stacks,queues,linked-listStacks,queues,linked-list
Stacks,queues,linked-list
 
stacks and queues
stacks and queuesstacks and queues
stacks and queues
 
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
 
Stacks Data structure.pptx
Stacks Data structure.pptxStacks Data structure.pptx
Stacks Data structure.pptx
 
Queue
QueueQueue
Queue
 
Stack in C.pptx
Stack in C.pptxStack in C.pptx
Stack in C.pptx
 
Stack data structure
Stack data structureStack data structure
Stack data structure
 
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
 
stacks and queues
stacks and queuesstacks and queues
stacks and queues
 
Data structure lecture7
Data structure lecture7Data structure lecture7
Data structure lecture7
 
Stack
StackStack
Stack
 

More from Selvin Josy Bai Somu (8)

Client sidescripting javascript
Client sidescripting javascriptClient sidescripting javascript
Client sidescripting javascript
 
Web technology
Web technologyWeb technology
Web technology
 
Files in c++
Files in c++Files in c++
Files in c++
 
Constructor and destructor
Constructor and destructorConstructor and destructor
Constructor and destructor
 
Inheritance
InheritanceInheritance
Inheritance
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Function overloading
Function overloadingFunction overloading
Function overloading
 
Basics of c++
Basics of c++Basics of c++
Basics of c++
 

Recently uploaded

Basic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
Basic Civil Engg Notes_Chapter-6_Environment Pollution & EngineeringBasic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
Basic Civil Engg Notes_Chapter-6_Environment Pollution & EngineeringDenish Jangid
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...Nguyen Thanh Tu Collection
 
How to Manage Notification Preferences in the Odoo 17
How to Manage Notification Preferences in the Odoo 17How to Manage Notification Preferences in the Odoo 17
How to Manage Notification Preferences in the Odoo 17Celine George
 
Industrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training ReportIndustrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training ReportAvinash Rai
 
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfbu07226
 
Gyanartha SciBizTech Quiz slideshare.pptx
Gyanartha SciBizTech Quiz slideshare.pptxGyanartha SciBizTech Quiz slideshare.pptx
Gyanartha SciBizTech Quiz slideshare.pptxShibin Azad
 
Application of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matricesApplication of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matricesRased Khan
 
Open Educational Resources Primer PowerPoint
Open Educational Resources Primer PowerPointOpen Educational Resources Primer PowerPoint
Open Educational Resources Primer PowerPointELaRue0
 
Morse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptxMorse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptxjmorse8
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsCol Mukteshwar Prasad
 
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfDanh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfQucHHunhnh
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleCeline George
 
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...Denish Jangid
 
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxMatatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxJenilouCasareno
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfjoachimlavalley1
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePedroFerreira53928
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxEduSkills OECD
 

Recently uploaded (20)

Basic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
Basic Civil Engg Notes_Chapter-6_Environment Pollution & EngineeringBasic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
Basic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
B.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdfB.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdf
 
How to Manage Notification Preferences in the Odoo 17
How to Manage Notification Preferences in the Odoo 17How to Manage Notification Preferences in the Odoo 17
How to Manage Notification Preferences in the Odoo 17
 
Industrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training ReportIndustrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training Report
 
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
 
Gyanartha SciBizTech Quiz slideshare.pptx
Gyanartha SciBizTech Quiz slideshare.pptxGyanartha SciBizTech Quiz slideshare.pptx
Gyanartha SciBizTech Quiz slideshare.pptx
 
Application of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matricesApplication of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matrices
 
Open Educational Resources Primer PowerPoint
Open Educational Resources Primer PowerPointOpen Educational Resources Primer PowerPoint
Open Educational Resources Primer PowerPoint
 
Morse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptxMorse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptx
 
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
Operations Management - Book1.p  - Dr. Abdulfatah A. SalemOperations Management - Book1.p  - Dr. Abdulfatah A. Salem
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfDanh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...
 
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxMatatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 

Data structure stack&queue basics

  • 1. DATA STRUCTURE STACKS AND QUEUES Prepared by : SELVIN JOSY BAI.S
  • 2. STACK  It is a linear data structure in which an elements may be inserted or deleted only at one end called the top of the stack.  This data structure implemented in LIFO (Last In First Out) manner  LIFO means element last inserted would be the first one to be deleted.  The Stack is also a dynamic data structure as it can grow or shrink.
  • 3.  Real life example :  A stack OF DISCS IN HOLDER  A stack of TOKENS IN HOLDER  Two basic operations of stack  PUSHING : An Insertion in a stack is called PUSHING.  POPPING : A Deletion from a stack is called POPPING.
  • 4. PUSHING ALGORITHM 1. Read ITEM 2. If TOP = N then Print “OVERFLOW” and Stop 3. Else set TOP = TOP + 1 //Creating a space for a new element 4. Set STACK [ TOP ] = ITEM //Inserting the new ITEM 5. Stop 1 2 3 4 5 TOP N 5 NULL
  • 5. POPPING ALGORITHM 1. If TOP = NULL then Print “UNDERFLOW” and return 2. Else set ITEM =STACK [ TOP ] 3. Set TOP = TOP - 1 4. Stop 1 2 3 4 5 TOP
  • 6. APPLICATIONS OF STACK  TO REVERSING A STRING  TO EVALUATE NOTATIONAL EXPRESSION(INFIX, PREFIX, & POSTFIX)  TO CONVERT FROM ONE EXPRESSION TO ANOTHER.
  • 7. QUEUE  It is a linear data structure in which an element may be inserted only at one end, called the REAR end and deletions can be take place at the other end, called the FRONT end.  This data structure implemented in FIFO (First In First Out) manner  FIFO means element first inserted would be the first one to be deleted.  The Queue is also a dynamic data structure as it can grow or shrink.  However, if additions and deletions are made at both ends of a queue, then such a queue is called Double Ended Queue or simply DEQUE.
  • 8. The following operations can be performed on Queues 1. Addition of an element at the REAR end of the queue 2. Deletion of an element from the FRONT end of the queue Real life example : • People waiting at a railway station counter for taking tickets
  • 9. Algorithm for INSERTION 1. If FRONT = 1 and REAR = N or If FRONT = REAR + 1 then Print “OVERFLOW” ; stop 2. if FRONT = NULL then set FRONT = 1 and REAR = 1 3. Else if REAR = N then set REAR = 1 4. Else set REAR = REAR + 1 5. Endif 6. Set QUEUE [ REAR ] = ITEM 7. Stop
  • 10. Algorithm for DELETION 1. If FRONT = NULL then Print “UNDERFLOW” ; stop 2. set ITEM = QUEUE [FRONT] 3. If FRONT = REAR then set FRONT = NULL and REAR = NULL 4. Else if FRONT = N then set FRONT = 1 5. Else set FRONT = FRONT + 1 6. Stop
  • 11. APPLICATIONS OF QUEUE  IT OCCURS IN THE JOB SCHEDULING  THE COMPUTER OS USE THIS CONCEPT IN SCHEDULING THE MEMORY, PROCESSOR AND THE FILES.  USED FOR SCHEDULING JOBS AND SERVICES.
  • 12. EXERCISE - 1  In CD pack, the CDs are placed one over the other through a central axis. Assume that there are 25 CDs in the pack. a. Name the data structure that resembles with the CD pack. b. Considering the CD pack as an array in C++, how will you name the position of the last CD and what will be its value? c. Write an algorithm to remove a CD from the pack and name the operation performed.
  • 13. EXERCISE - 2  While waiting for a ticket at the railway station ticket counter, you are following the principle as that of a data structure a. Name the data structure and the principle b. Write a C++ function to add a new element in this data structure. c. Name the situation where there is no space for adding new element
  • 14. Some more Questions 1. What is overflow and underflow? 2. Explain the terms PUSH and POP? 3. What are the applications of stacks and queues? 4. Name the data structure that resembles a person placing plates in a vessel. Write an algorithm for inserting a plate.