QUEUE Education is the best friend. An educated person is respected everywhere. Education beats the beauty and the youth. Chanakya.

Slides:



Advertisements
Similar presentations
Data Structures Through C
Advertisements

Queues Printer queues Several jobs submitted to printer Jobs form a queue Jobs processed in same order as they were received.
§1 Greedy Algorithms ALGORITHM DESIGN TECHNIQUES
Stacks, Queues, and Linked Lists
Chapter 3 – Lists A list is just what the name implies, a finite, ordered sequence of items. Order indicates each item has a position. A list of size 0.
§3 The Stack ADT 1. ADT A stack is a Last-In-First-Out (LIFO) list, that is, an ordered list in which insertions and deletions are.
Queue Definition Ordered list with property: –All insertions take place at one end (tail) –All deletions take place at other end (head) Queue: Q = (a 0,
Queues. Queue Definition Ordered list with property: All insertions take place at one end (tail) All insertions take place at one end (tail) All deletions.
Templates in C++ Template function in C++ makes it easier to reuse classes and functions. A template can be viewed as a variable that can be instantiated.
Data Structures Lecture 13: QUEUES Azhar Maqsood NUST Institute of Information Technology (NIIT)
CSCE 3110 Data Structures & Algorithm Analysis Stacks and Queues Reading: Chap.3 Weiss.
Queues1 Part-B2 Queues. Queues2 The Queue ADT (§4.3) The Queue ADT stores arbitrary objects Insertions and deletions follow the first-in first-out scheme.
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.
Array based Queues A circular implementation. Implementation Option 1 As with a array based stack, there are multiple ways that a queue can be implemented.
Data Structure (Part I) Stacks and Queues. Introduction to Stack An stack is a ordered list in which insertion and deletions are made at one end. –The.
Data Structures (Second Part) Lecture 3 : Array, Linked List, Stack & Queue Bong-Soo Sohn Assistant Professor School of Computer Science and Engineering.
Introduction to C Programming CE Lecture 12 Circular Queue and Priority Queue Data Structures.
1 Queues – Chapter 3 A queue is a data structure in which all additions are made at one end called the rear of the queue and all deletions are made from.
CSCE 3110 Data Structures & Algorithm Analysis Queues Reading: Chap. 3 Weiss.
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.
What is a Queue? n Logical (or ADT) level: A queue is an ordered group of homogeneous items (elements), in which new elements are added at one end (the.
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.
LINKED QUEUES P LINKED QUEUE OBJECT Introduction Introduction again, the problem with the previous example of queues is that we are working.
Data Structures and Algorithms Lecture (Queues) Instructor: Quratulain.
Data Structure Dr. Mohamed Khafagy.
Queue Overview Queue ADT Basic operations of queue
COP3538 – Data Structures Using OOP Chapter 4 – Stacks and Queues.
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.
CS Data Structures Chapter 3 Stacks and Queues.
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.
Main Index Contents 11 Main Index Contents Model for a Queue Model for a Queue The Queue The Queue ADTQueue ADT (3 slides) Queue ADT Radix Sort Radix Sort.
Chapter 3. Templates in C++ Template function in C++ makes it easier to reuse classes and functions. A template can be viewed as a variable that can be.
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.
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.
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.
© 2004 Goodrich, Tamassia Queues1. © 2004 Goodrich, Tamassia Queues2 The Queue ADT (§4.3) The Queue ADT stores arbitrary objects Insertions and deletions.
© 2006 Pearson Addison-Wesley. All rights reserved8 A-1 Chapter 8 Queues.
Queues Tonga Institute of Higher Education. Definitions Queue - A data structure that stores a number of items. The first item entered into a queue is.
Data Structures Using C++
Stacks And Queues Chapter 18.
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.
Data Structures Chapter 6. Data Structure A data structure is a representation of data and the operations allowed on that data. Examples: 1.Array 2.Record.
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.
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.
Chap 3 Stack and Queue. Templates in C++ Template function in C++ makes it easier to reuse classes and functions. A template can be viewed as a variable.
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.
Queues Manolis Koubarakis Data Structures and Programming Techniques 1.
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 and Queues ● Introduction to stacks ● Stack implementation ● 4 Standard operations on a stack ● A stack program ● Introduction to queues ● Queue.
STACKS & QUEUES for CLASS XII ( C++).
Arrays.
Stacks and Queues.
CSCE 3110 Data Structures & Algorithm Analysis
Queues Mohammad Asad Abbasi Lecture 5
Queues.
Queues 11/22/2018 6:47 AM 5.2 Queues Queues Dr Zeinab Eid.
COMPUTER 2430 Object Oriented Programming and Data Structures I
CSC 143 Queues [Chapter 7].
Queues 12/3/2018 Queues © 2014 Goodrich, Tamassia, Goldwasser Queues.
Queues: Implemented using Arrays
Stack A data structure in which elements are inserted and removed only at one end (called the top). Enforces Last-In-First-Out (LIFO) Uses of Stacks Evaluating.
Chapter 8 Queues © 2006 Pearson Addison-Wesley. All rights reserved.
Queues Jyh-Shing Roger Jang (張智星)
Circular Queues: Implemented using Arrays
Data Structures & Programming
Presentation transcript:

QUEUE Education is the best friend. An educated person is respected everywhere. Education beats the beauty and the youth. Chanakya

Queue A queue is an ordered list in which all insertions take place at one end and all deletions take place at the opposite end. It is also known as First-In-First-Out (FIFO) lists. a0a0 a1a1 a2a2 a n-1 front rear

A BABA CBACBA DCBADCBA DCBDCB Rear front rear front rear front rear front rear front *Figure : Inserting and deleting elements in a queue Queue: a First-In-First-Out (FIFO) list Rear front

*Figure 3.5: Insertion and deletion from a sequential queue Application: Job scheduling

EMPTY QUEUE [2] [3] [2] [3] [1] [4] [0] [5] [0] [5] front = 0 rear = 0 rear = 3 *Figure: Empty and nonempty circular queues J2 J1 J3 Implementation 2: regard an array as a circular queue front: one position counterclockwise from the first element rear:current end

FULL QUEUE FULL QUEUE [2] [3] [2] [3] [1] [4][1] [4] [0] [5] front =0 rear = 5 front =4 rear =3 *Figure: Full circular queues and then we remove the item J2 J3 J1 J4 J5 J6 J5 J7 J8 J9 Problem: one space is left when queue is full

void addq(element item) { /* add an item to the queue */ int k = (rear +1) % MAX_QUEUE_SIZE; if (front == k) /* reset rear and print error */ return; rear = k; queue[rear] = item; } *Program: Add to a circular queue Add to a circular queue [2] [3] [1] [4] [0] [5] front = 0 rear = 3 J2 J1 J3

element deleteq() { element item; /* remove front element from the queue and put it in item */ if (front == rear) return queue_empty( ); /* queue_empty returns an error key */ front = (front+1) % MAX_QUEUE_SIZE; return queue[front]; } *Program 3.6: Delete from a circular queue CHAPTER 38 Delete from a circular queue [2] [3] [1] [4] [0] [5] front = 0 rear = 3 J2 J1 J3

Circular Queue To resolve the issue of moving elements in the queue, circular queue assigns next element to q[0] when rear == MaxSize – 1. Pointer front will always point one position counterclockwise from the first element in the queue. Queue is empty when front == rear. But it is also true when queue is full. This will be a problem.

Circular Queue (Cont.) n-1 n-2 n-3 n-4 front = 0; rear = n-1 n-2 n-3 n-4 front = n-4; rear = 0 J1 J2 J3 J4 J1 J2 J3 J4

Circular Queue (Cont.) To resolve the issue when front == rear on whether the queue is full or empty, one way is to use only MaxSize – 1 elements in the queue at any time. Each time when adding an item to the queue, newrear is calculated before adding the item. If newrear == front, then the queue is full. Another way to resolve the issue is using a flag to keep track of last operation. The drawback of the method is it tends to slow down Add and Delete function.