Queue 09/10/081. Queue (Linear Queue) It is a linear data structure consisting of list of items. In queue, data elements are added at one end, called.

Slides:



Advertisements
Similar presentations
Data Structures Through C
Advertisements

QUEUE Education is the best friend. An educated person is respected everywhere. Education beats the beauty and the youth. Chanakya.
1 Array-based Implementation An array Q of maximum size N Need to keep track the front and rear of the queue: f: index of the front object r: index immediately.
Ceng-112 Data Structures I Chapter 5 Queues.
COSC 1P03 Data Structures and Abstraction 9.1 The Queue Whenever you are asked if you can do a job, tell 'em, "Certainly, I can!" Then get busy and find.
Data Structures Queue Namiq Sultan 1. Queue A queue is an ordered collection of items into which items may be added at one end (rear) and from which items.
Alford Academy Business Education and Computing1 Advanced Higher Computing Based on Heriot-Watt University Scholar Materials Stack and Queues.
5/4/2015ITK 2751 Queue a FIFO (First In First Out) efbh front rear poll, remove offer peek, element capacity size.
A queue is an ADT which allows data values to be accessed only one at a time and only the first inserted. The rule imposed on a queue is: First In First.
Queues CS-212 Dick Steflik. Queues First In, First Out operation – FIFO As items are added they are chronologically ordered, items are removed in their.
Lecture - 9 On Queues. Prepared by, Jesmin Akhter, Lecturer, IIT,JU QUEUES A Queue is a linear list of elements in which deletions can take place only.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
MSc.It :- Ali Abdul Karem Habib Kufa University / mathematics & Science Of Computer.
Data Structure Dr. Mohamed Khafagy.
Queue Overview Queue ADT Basic operations of queue
DATA STRUCTURE & ALGORITHMS
Queues The content for these slides was originally created by Gerard Harrison. Ported to C# by Mike Panitz.
C o n f i d e n t i a l Developed By Nitendra NextHome Subject Name: Data Structure Using C Unit : Overview of Queues.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
Queues The content for these slides was originally created by Gerard Harrison. Ported to C# by Mike Panitz.
Queue using an array. .head.tail Pointers head and tail always point to the first empty slot before or after elements in the list. Thus, initially they.
Queues CS-240 & CS-341 Dick Steflik. Queues First In, First Out operation – FIFO As items are added they are chronologically ordered, items are removed.
CHAPTER 05 Compiled by: Dr. Mohammad Omar Alhawarat Stacks & Queues.
CHP-4 QUEUE.
TK1924 Program Design & Problem Solving Session 2011/2012 L6: Queues.
Stacks, Queues & Recursion
Queue 1 Operations on Queues A Dequeue Operation An Enqueue Operation Array Implementation Link list Implementation Examples.
Data Structures Using C++ 2E Chapter 8 Queues. Data Structures Using C++ 2E2 Objectives Learn about queues Examine various queue operations Learn how.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 18: Stacks and Queues (part 3)
1 Stacks and Queues Based on D.S. Malik, Java Programming: Program Design Including Data Structures.
Data Structures Using C++
Scis.regis.edu ● CS-362: Data Structures Week 8 Dr. Jesús Borrego 1.
Queues Linear list. One end is called front. Other end is called rear. Additions are done at the rear only. Removals are made from the front only. FIFO.
CHP-4 QUEUE. 1.INTRODUCTION  A queue is a linear list in which elements can be added at one end and elements can be removed only at other end.  That.
Computer Science Department Data Structures and Algorithms Queues Lecture 5.
Kruse/Ryba ch031 Object Oriented Data Structures Queues Implementations of Queues Circular Implementation of Queues.
Kruse/Ryba ch031 Object Oriented Data Structures Queues Implementations of Queues Circular Implementation of Queues.
Data Structures. Abstract Data Type A collection of related data is known as an abstract data type (ADT) Data Structure = ADT + Collection of functions.
Give Eg:? Queues. Introduction DEFINITION: A Queue is an ordered collection of element in which insertions are made at one end and deletions are made.
Computer Engineering Rabie A. Ramadan Lecture 6.
1 Data Structures CSCI 132, Spring 2014 Lecture 7 Queues.
Queue ADT for lining up politely. COSC 2006 queue2 Queue – simple collection class  first-in first-out (FIFO) structure insert new elements at one end.
Part 2. Deletion from a linked list Let LIST be a linked list with a node N between nodes A and B. suppose node N is to be deleted from the linked list.
 In general, Queue is line of person waiting for their turn at some service counter like ticket window at cinema hall, at bus stand or at railway station.
© Oxford University Press All rights reserved. Data Structures Using C, 2e Reema Thareja.
Circular Queues Maitrayee Mukerji. Queues First In – First Out (FIFO) The first element to be inserted is the first one to be retrieved Insertion at one.
Data Abstraction and Problem Solving with JAVA Walls and Mirrors Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley Data Abstraction and Problem.
STACKS & QUEUES for CLASS XII ( C++).
Queue Adam M.B..
Review Array Array Elements Accessing array elements
What is a Queue? Queue is a linear data structure in which the insertion and deletion operations are performed at two different ends. In a queue data structure,
Data Structures Using C++ 2E
Data Structures Using C, 2e
Queues.
Queues Chapter 4.
Using Queues: Coded Messages
Chapter 15 Lists Objectives
UNIT-3 LINKED LIST.
Lectures Queues Chapter 8 of textbook 1. Concepts of queue
Stacks and Queues.
Data Structures Interview / VIVA Questions and Answers
Queues Chapter 4.
QUEUE.
CSCE 3110 Data Structures & Algorithm Analysis
DATA STRUCTURE QUEUE.
Figure 7.1 Some queue operations. Figure 7.1 Some queue operations.
Chapter 8 Queues © 2006 Pearson Addison-Wesley. All rights reserved.
QUEUE Visit for more Learning Resources Free Powerpoint Templates.
Data Structures Using C++ 2E
Presented by : Aman Gupta PGT CS KV No.1, Narimedu, Madurai
Presentation transcript:

Queue 09/10/081

Queue (Linear Queue) It is a linear data structure consisting of list of items. In queue, data elements are added at one end, called the rear and removed from another end, called the front of the list. Two basic operations are associated with queue: 1. “Insert” operation is used to insert an element into a queue. 2. “Delete” operation is used to delete an element from a queue. ● FIFO list Example: Queue: AAA, BBB, CCC, DDD, EEE AAABBBCCCDDDEEE Rear Front EEE DDD CCC BBB AAA Rear Front 09/10/

3 Algorithms for Insert and Delete Operations in Linear Queue For Insert Operation Insert-Queue(Queue, Rear, Front, N, Item) Here, Queue is the place where to store data. Rear represents the location in which the data element is to be inserted and Front represents the location from which the data element is to be removed. Here N is the maximum size of the Queue and finally, Item is the new item to be added. 1. If Rear = N then Print: Overflow and Return. /*…Queue already filled..*/ 2. Set Rear := Rear Set Queue[Rear] := Item 4. Return.

09/10/084 For Delete Operation Delete-Queue(Queue, Front, Rear, Item) Here, Queue is the place where data are stored. Rear represents the location in which the data element is to be inserted and Front represents the location from which the data element is to be removed. Front element is assigned to Item. 1. If Front = N+1 then Print: Underflow and Return. /*…Queue Empty 2. Set Item := Queue[Front] 3. Set Front := Front Return.

09/10/085 Example: Consider the following queue (linear queue). Rear = 4 and Front = 1 and N = (1) Insert 20. Now Rear = 5 and Front = (2) Delete Front Element. Now Rear = 5 and Front = (3) Delete Front Element. Now Rear = 5 and Front = (4) Insert 60. Now Rear = 6 and Front =

09/10/086 Drawback of Linear Queue Once the queue is full, even though few elements from the front are deleted and some occupied space is relieved, it is not possible to add anymore new elements, as the rear has already reached the Queue’s rear most position. Circular Queue This queue is not linear but circular. Its structure can be like the following figure: Figure: Circular Queue having Rear = 5 and Front = 0 In circular queue, once the Queue is full the "First" element of the Queue becomes the "Rear" most element, if and only if the "Front" has moved forward. otherwise it will again be a "Queue overflow" state.

09/10/087 Algorithms for Insert and Delete Operations in Circular Queue For Insert Operation Insert-Circular-Q(CQueue, Rear, Front, N, Item) Here, CQueue is a circular queue where to store data. Rear represents the location in which the data element is to be inserted and Front represents the location from which the data element is to be removed. Here N is the maximum size of CQueue and finally, Item is the new item to be added. Initailly Rear = 0 and Front = If Front = 0 and Rear = 0 then Set Front := 1 and go to step If Front =1 and Rear = N or Front = Rear + 1 then Print: “Circular Queue Overflow” and Return. 3. If Rear = N then Set Rear := 1 and go to step Set Rear := Rear Set CQueue [Rear] := Item. 6. Return

09/10/088 For Delete Operation Delete-Circular-Q(CQueue, Front, Rear, Item) Here, CQueue is the place where data are stored. Rear represents the location in which the data element is to be inserted and Front represents the location from which the data element is to be removed. Front element is assigned to Item. Initially, Front = If Front = 0 then Print: “Circular Queue Underflow” and Return. /*..Delete without Insertion 2. Set Item := CQueue [Front] 3. If Front = N then Set Front = 1 and Return. 4. If Front = Rear then Set Front = 0 and Rear = 0 and Return. 5. Set Front := Front Return.

09/10/089 Example: Consider the following circular queue with N = Initially, Rear = 0, Front = Insert 10, Rear = 1, Front = Insert 50, Rear = 2, Front = Insert 20, Rear = 3, Front = Insert 70, Rear = 4, Front = Delete front, Rear = 4, Front = 2. Rear Front

09/10/ Insert 100, Rear = 5, Front = Insert 40, Rear = 1, Front = Insert 140, Rear = 1, Front = 2. As Front = Rear + 1, so Queue overflow. 10. Delete front, Rear = 1, Front = 3. Front Rear FrontRear Front 11. Delete front, Rear = 1, Front = Delete front, Rear = 1, Front = 5. Rear Front

09/10/0811 END!!!