© A+ Computer Science - www.apluscompsci.com. A queue is a group of same-type values. Values are added to the back of a queue and removed from the front.

Slides:



Advertisements
Similar presentations
STACKS & QUEUES. Stacks Abstract data types An abstract data type (ADT) is an abstraction of a data structure An ADT specifies : –Data stored –Operations.
Advertisements

Lists, Stacks, Queues Svetlin Nakov Telerik Corporation
Data Structures A data structure is a collection of data organized in some fashion that permits access to individual elements stored in the structure This.
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.
Stacks, Queues, and Deques. 2 A stack is a last in, first out (LIFO) data structure Items are removed from a stack in the reverse order from the way they.
CS 206 Introduction to Computer Science II 10 / 22 / 2008 Instructor: Michael Eckmann.
Queues. What is a queue? First-in first-out data structure (FIFO) New objects are placed at rear Removal restricted to front Examples?
CS 206 Introduction to Computer Science II 11 / 04 / 2009 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 10 / 20 / 2008 Instructor: Michael Eckmann.
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.
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (4) Data Structures 11/18/2008 Yang Song.
Queues.
Heaps & Priority Queues Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
CS 206 Introduction to Computer Science II 10 / 26 / 2009 Instructor: Michael Eckmann.
1 Data Structures  We can now explore some advanced techniques for organizing and managing information  Chapter 12 of the book focuses on: dynamic structures.
CSC 212 Stacks & Queues. Announcement Daily quizzes accepted electronically only  Submit via one or other Dropbox  Cannot force you to compile & test.
Chapter 24 Dispensers and dictionaries. This chapter discusses n Dictionaries n Dispensers u stacks u queues u priority queues.
© 2004 Pearson Addison-Wesley. All rights reserved12-1 Chapter 12 : Collections Intermediate Java Programming Summer 2007.
Chapter 6.6, (event-driven simulation) Queues 1CSCI 3333 Data Structures.
CSE 373 Data Structures and Algorithms Lecture 2: Queues.
Data Structures - Queues
90-723: Data Structures and Algorithms for Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 5: Stacks and Queues.
CHAPTER 05 Compiled by: Dr. Mohammad Omar Alhawarat Stacks & Queues.
Some Other Collections: Bags, Sets, Queues and Maps COMP T2 Lecture 4 School of Engineering and Computer Science, Victoria University of Wellington.
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’
CSS446 Spring 2014 Nan Wang  Java Collection Framework ◦ LinkedList ◦ Set ◦ Map 2.
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,
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.
Queue Definition A queue is a data structure with elements of the same type. Queue elements can only be entered at one end of the queue, called the back,
CSS446 Spring 2014 Nan Wang  Java Collection Framework ◦ Stack ◦ Queue & Priority Queue 2.
Heaps & Priority Queues
1 Stacks (Continued) and Queues Array Stack Implementation Linked Stack Implementation The java.util.Stack class Queue Abstract Data Type (ADT) Queue ADT.
CSE 373: Data Structures and Algorithms Lecture 2: Queues.
Priority Queues. Priority Queue ADT A priority queue stores a collection of entries Each entry is a pair (key, value) Main methods of the Priority Queue.
Some Other Collections: Bags, Sets, Queues and Maps COMP T2 Lecture 4 School of Engineering and Computer Science, Victoria University of Wellington.
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.
3/3/20161 Stacks and Queues Introduction to Data Structures Ananda Gunawardena.
Queues 1. Queue  a queue represents a sequence of elements where elements can be added at the back of the sequence and removed from the front of the.
1 Lecture 9: Stack and Queue. What is a Stack Stack of Books 2.
Queues and Priority Queue Implementations Chapter 14 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Queues By Jimmy M. Lu. Overview Definition Standard Java Queue Operations Implementation Queue at Work References.
G64ADS Advanced Data Structures
Set Collection A Bag is a general collection class that implements the Collection interface. A Set is a collection that resembles a Bag with the provision.
Stacks – review A Last-In First-Out (LIFO) structure Basic Operations:
QueueStack CS1020.
CSE 373: Data Structures and Algorithms
Stacks and Queues.
Data Structures and Database Applications Queues in C#
Topic 16 Queues "FISH queue: n.
Topic 16 Queues Adapted from Mike Scott’s materials.
CMSC 341 Lecture 5 Stacks, Queues
structures and their relationships." - Linus Torvalds
Queues, Deques and Priority Queues
Stacks – review A Last-In First-Out (LIFO) structure Basic Operations:
Queues, Deques and Priority Queues
structures and their relationships." - Linus Torvalds
Revised based on textbook author’s notes.
ITEC 2620M Introduction to Data Structures
Queues 3/9/15 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser,
Queues FIFO Enqueue Dequeue Peek.
Data Structures and Algorithms for Information Processing
Queues CSC212.
Priority Queues & Heaps
See requirements for practice program on next slide.
More Data Structures (Part 1)
Visit for more Learning Resources
Queues and Priority Queue Implementations
structures and their relationships." - Linus Torvalds
Lecture 9: Stack and Queue
Data Structures & Programming
Presentation transcript:

© A+ Computer Science -

A queue is a group of same-type values. Values are added to the back of a queue and removed from the front. The first value added would be the first item removed. Queues work in a FIFO manner.

© A+ Computer Science - In England, when you are to stand in a line, they tell you to go get in the queue.

© A+ Computer Science - An empty integer queue. Queue queue; queue = new LinkedList (); queue will only store Integer values.

© A+ Computer Science - queue.add(25); add adds an item to the queue. enqueue is a very common name given to the operation of adding items to a queue. 25

© A+ Computer Science - queue.add(14); add adds an item to the queue. 2514

© A+ Computer Science - queue.add(67); add adds an item to the queue

© A+ Computer Science - queue.remove(); remove removes an item from the queue. dequeue is a very common name given to the operation of removing items from a queue. 1467

© A+ Computer Science - queue.remove(); remove removes an item from the queue. 67

© A+ Computer Science - queue.add(99); add adds an item to the queue. 6799

© A+ Computer Science - The Queue interface was designed to allow the use of a queue in java. The LinkedList class implements the Queue interface. If you need a queue, just make a Queue reference to a LinkedList.

© A+ Computer Science -

Linked List as a Queue frequently used methods NameUse add(x)adds item x to the queue remove()removes and returns front item peek()returns the front item with no remove size()returns the # of items in the queue isEmpty()checks to see if the queue is empty import java.util.Queue;

© A+ Computer Science - Queue queue; queue = new LinkedList (); queue.add(11); queue.add(10); queue.add(7); out.println(queue); OUTPUT [11, 10, 7]

© A+ Computer Science - Queue queue; queue = new LinkedList (); queue.add(11); queue.add(10); queue.add(7); out.println(queue.remove()); out.println(queue); OUTPUT 11 [10, 7]

© A+ Computer Science -

Queue queue; queue = new LinkedList (); queue.add(11); queue.add(7); out.println(queue); out.println(queue.peek()); queue.remove(); out.println(queue.peek()); queue.remove(); out.println(queue); OUTPUT [11, 7] 11 7 []

© A+ Computer Science -

Queue queue; queue = new LinkedList (); queue.add(11); queue.add(10); queue.add(7); while(!queue.isEmpty()) { out.println(queue.remove()); } OUTPUT

© A+ Computer Science -

A PriorityQueue is a queue structure that organizes the data inside by the natural ordering or by some specified criteria. The Java PriorityQueue is a min heap as it removes the smallest items first. The Java PriorityQueue stores Comparables.

© A+ Computer Science -

PriorityQueue frequently used methods NameUse add(x)adds item x to the pQueue remove()removes and returns min priority item peek()returns the min item with no remove size()returns the # of items in the pQueue isEmpty()checks to see if the pQueue is empty

© A+ Computer Science - PriorityQueue pQueue; pQueue = new PriorityQueue (); pQueue.add(11); pQueue.add(10); pQueue.add(7); out.println(pQueue); OUTPUT [7, 11, 10]

© A+ Computer Science - PriorityQueue pQueue; pQueue = new PriorityQueue (); pQueue.add(11); pQueue.add(10); pQueue.add(7); out.println(pQueue); out.println(pQueue.remove()); out.println(pQueue); OUTPUT [7, 11, 10] 7 [10, 11]

© A+ Computer Science -

PriorityQueue pQueue; pQueue = new PriorityQueue (); pQueue.add(11); pQueue.add(10); pQueue.add(7); while(!pQueue.isEmpty()) { out.println(pQueue.remove()); } OUTPUT

© A+ Computer Science -