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.

Slides:



Advertisements
Similar presentations
Queues Printer queues Several jobs submitted to printer Jobs form a queue Jobs processed in same order as they were received.
Advertisements

STACKS & QUEUES. Stacks Abstract data types An abstract data type (ADT) is an abstraction of a data structure An ADT specifies : –Data stored –Operations.
Stacks, Queues, and Linked Lists
Queues and Linked Lists
Senem Kumova Metin Spring2009 STACKS AND QUEUES Chapter 10 in A Book on C.
Data Structures Lecture 13: QUEUES Azhar Maqsood NUST Institute of Information Technology (NIIT)
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.
queues1 Queues Data structures that wait their turn.
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.
CHAPTER 7 Queues.
Chapter 7 Queues. Data Structure 2 Chapter Outline  Objectives  Follow and explain queue-based algorithms using the front, rear, entering the queue,
ADT Queue 1. What is a Queue? 2. STL Queue 3. Array Implementation of Queue 4. Linked List Implementation of Queue 5. Priority Queue.
ADT Stacks and Queues. Stack: Logical Level “An ordered group of homogeneous items or elements in which items are added and removed from only one end.”
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
Queues 4/14/2017 5:24 PM 5.2 Queues Queues Dr Zeinab Eid.
1 Queues (5.2) CSE 2011 Winter May Announcements York Programming Contest Link also available from.
Queue Overview Queue ADT Basic operations of queue
Queues. What is a queue? First-in first-out data structure (FIFO) New objects are placed at rear Removal restricted to front Examples?
© 2006 Pearson Addison-Wesley. All rights reserved8-1 Chapter 8 Queues CS102 Sections 51 and 52 Marc Smith and Jim Ten Eyck Spring 2008.
Queues. What is a queue? First-in first-out data structure (FIFO) New objects are placed at rear Removal restricted to front Examples?
Unit 11 1 Unit 11: Data Structures H We explore some simple techniques for organizing and managing information H This unit focuses on: Abstract Data Types.
Queues.
Cmpt-225 Queues. A queue is a data structure that only allows items to be inserted at the end and removed from the front Queues are FIFO (First In First.
Chapter 12 C Data Structures Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
Fall 2007CS 2251 Queues Chapter 6. Fall 2007CS 2252 Chapter Objectives To learn how to represent a waiting line (queue) and how to use the methods in.
1 Foundations of Software Design Fall 2002 Marti Hearst Lecture 13: Queues and Vectors.
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.
1 Stack Data : a collection of homogeneous elements arranged in a sequence. Only the first element may be accessed Main Operations: Push : insert an element.
© 2004 Pearson Addison-Wesley. All rights reserved12-1 Chapter 12 : Collections Intermediate Java Programming Summer 2007.
CSE 373 Data Structures and Algorithms Lecture 2: Queues.
Chapter 12 Data Structure Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
90-723: Data Structures and Algorithms for Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 5: Stacks and Queues.
CS 1031 Queues Definition of a Queue Examples of Queues Design of a Queue Class Different Implementations of the Queue Class.
© 2006 Pearson Addison-Wesley. All rights reserved8 A-1 Chapter 8 Queues (slightly modified by Dan Fleck)
DATA STRUCTURES AND ALGORITHMS Lecture Notes 4 Prepared by İnanç TAHRALI.
Cosc237/data structures1 Data Types Every data type has two characteristics: 1.Domain - set of all possible values 2.set of allowable operations Built-in.
Data Structures (part 2). Stacks An Everyday Example Your boss keeps bringing you important items to deal with and keeps saying: “Put that last ‘rush’
A data structure is a type of data storage ….similar to an array. There are many data structures in Java (Stacks, Queues, LinkedList, Sets, Maps, HashTables,
Lecture7: Queue Bohyung Han CSE, POSTECH CSED233: Data Structures (2014F)
Lab 7 Queue ADT. OVERVIEW The queue is one example of a constrained linear data structure. The elements in a queue are ordered from least recently added.
Stacks And Queues Chapter 18.
Cousin of the Stack.  An abstract data type (container class) in which items are entered at one end and removed from the other end  First In First.
CSS446 Spring 2014 Nan Wang  Java Collection Framework ◦ Stack ◦ Queue & Priority Queue 2.
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.
UNIT II Queue. Syllabus Contents Concept of queue as ADT Implementation using linked and sequential organization. – linear – circular queue Concept –
CSE 373: Data Structures and Algorithms Lecture 2: Queues.
Chapter 7 Queues Introduction Queue applications Implementations.
M180: Data Structures & Algorithms in Java Queues Arab Open University 1.
1 Midterm 1 on Friday February 12 Closed book, closed notes No computer can be used 50 minutes 4 questions Write a function Write program fragment Explain.
Lecture 21 Data Structures, Algorithms and Complexity Stacks and Queues GRIFFITH COLLEGE DUBLIN.
1 Queues (Continued) Queue ADT Linked queue implementation Array queue implementation Circular array queue implementation Deque Reading L&C , 9.3.
1 Lecture 9: Stack and Queue. What is a Stack Stack of Books 2.
© 2004 Goodrich, Tamassia Queues. © 2004 Goodrich, Tamassia Stacks2 The Queue ADT The Queue ADT stores arbitrary objects Insertions and deletions follow.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 240 Abstract Data Types Queues Dale Roberts, Lecturer
Queues1 © 2014 Goodrich, Tamassia, Goldwasser Presentation for use with the textbook Data Structures and Algorithms in Java, 6 th edition, by M. T. Goodrich,
CSE 373: Data Structures and Algorithms
Queue data structure.
Stack and Queue APURBO DATTA.
Data Structures and Database Applications Queues in C#
Queue, Deque, and Priority Queue Implementations
Queue, Deque, and Priority Queue Implementations
Queues.
Queues 11/22/2018 6:47 AM 5.2 Queues Queues Dr Zeinab Eid.
CSC 143 Queues [Chapter 7].
18.5 Linked Queues Like a stack, a queue can be implemented using pointers and nodes Allows dynamic sizing, avoids issue of wrapping indices NULL front.
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.
CS210- Lecture 5 Jun 9, 2005 Agenda Queues
Lecture 9: Stack and Queue
Presentation transcript:

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 (rear) remove elements from opposite end (front) no access to interior of collection frontrear insert new element remove element 40

COSC 2006 queue3 Queue applications  local area network files waiting for printing are in a queue  multi-tasking operating system programs waiting for processor pipes between processes  simulations people in line for service – Tim Hortons, store checkout, bank aircraft taxiing for take-off

COSC 2006 queue4 Queues and Stacks  queue  stack frontrear insert new element remove element front / top insert new element remove element 94

COSC 2006 queue5 Queue methods  public void insert (Object item) add new item to rear of queue (enqueue)  public Object getFront() remove item from front of queue (dequeue)  public boolean isEmpty() true when no items in queue  public int size() number of items in queue

COSC 2006 queue6 Linked list implementation of a queue public class Queue { int manyNodes; Node front, rear; } manyNodes front rear 4 aaaxxxttttmm

COSC 2006 queue7 Linked list queue invariants public class Queue { //1. number of items stored in manyNodes //2. items stored in linked list with: // front of queue at head node // rear of queue at final node //3. front and rear reference // head and tail of queue; // both null if queue is empty int manyNodes; Node front, rear; }

COSC 2006 queue8 (new) empty queue  Queue q = new Queue(); manyNodes front rear 0 q public Queue() { manyNodes = 0; front = null; rear = null; }

COSC 2006 queue9 Insertion into queue  q.insert(“bbb”); manyNodes front rear 4 aaaxxxttttmm q bbb 5

Insertion into queue  q.insert(“bbb”); manyNodes front rear 4 aaaxxxttttmm q bbb 5 public void insert(Object item) { if(isEmpty()) { front = new Node(Item,null); rear = front; } else { rear.addNodeAfter(item); rear = rear.getLink(); } manyNodes++; }

COSC 2006 queue11 Insertion into queue - performance public void insert(Object item) { if(isEmpty()) { front = new Node(Item,null); rear = front; } else { rear.addNodeAfter(item); rear = rear.getLink(); } manyNodes++; } efficient O(1) independent of number of items (queue length)

COSC 2006 queue12 Queue – the java class  class Queue.java as linked listQueue.java  adapted from Main classes for queues

COSC 2006 queue13 Array implementation of a queue public class Queue { Object[] data; int manyItems; int front, rear; } data front rear 2 5 aaaxxxttttmm 2 5 manyItems 4 4

COSC 2006 queue14 Array implementation of a queue queue ‘drifts’ along the array but insertion and deletion are efficient O(1) data front rear 2 5 aaaxxxttttmm 2 5 manyItems 4 4

COSC 2006 queue15 Array drift of a queue (1) to avoid interruption at the end of the array, use a circular array data front rear 2 5 aaa xxx tttt mm 2 5 manyItems 4

COSC 2006 queue16 Array drift of a queue (2) after more insertion and deletion… data front rear ww dd sss 14 manyItems 3 12

COSC 2006 queue17 Array drift of a queue (3) after one more insertion data front rear 12 0 ww dd sss 0 manyItems 4 12 nn

COSC 2006 queue18 Coding the array Queue java code example Queue.java.arrayQueue.java.array  invariant  nextIndex  insert  getFront  ensureCapacity