Queues What are queues? Queue Implementation Using Linked Lists. Applications of Queues.

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

Queues and Linked Lists
Breadth First Search AB F I EH DC G FIFO Queue - front.
A queue is a linear, homogeneous, container that stores and dispenses its content in a FIFO manner. FIFO - First In First Out The first (most distant)
Ics202 Data Structures. hh tail head (b) LinkedList head tail Element datum next 3 Integer Element datum next 1 Integer Element datum next 4 Integer.
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.
CSC 212 – Data Structures. Using Stack Stack Limitations  Great for Pez dispensers, JVMs,& methods  All of these use most recent item added only 
CS Data Structures II Review COSC 2006 April 14, 2017
1 Breadth First Search AB F I EH DC G FIFO Queue - front.
COMP 103 Linked Stack and Linked Queue.
Queues Chapter 6. Chapter Objectives  To learn how to represent a waiting line (queue) and how to use the methods in the Queue interface for insertion.
Introduction to Stacks What is a Stack Stack implementation using arrays. Application of Stack.
Queue C and Data Structures Baojian Hua
Introduction to Stacks What are Stacks? Stack implementation using arrays. Stack application.
Fall 2007CS 2251 Iterators and Tree Traversals. Fall 2007CS 2252 Binary Trees In a binary tree, each node has at most two subtrees A set of nodes T is.
CS102 – Data Structures Lists, Stacks, Queues, Trees, Hash Collections Framework David Davenport Spring 2002.
Queues.
Introduction to Stacks What is a Stack Stack implementation using array. Stack implementation using linked list. Applications of Stack.
Queues What is a queue? Queue Implementations: –As Array –As Circular Array –As Linked List Applications of Queues. Priority queues.
1 Introduction to Stacks What is a Stack? Stack implementation using array. Stack implementation using linked list. Applications of Stacks.
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 Chapter 6. Chapter 6: Queues2 Chapter Objectives To learn how to represent a waiting line (queue) and how to use the methods in the Queue interface.
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.
CSC 212 Stacks & Queues. Announcement Daily quizzes accepted electronically only  Submit via one or other Dropbox  Cannot force you to compile & test.
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.
Queues What is a Queue? Queue Implementations: Queue As Array
Stacks, Queues, and Deques
Data Structures - Queues
Ics202 Data Structures. U n i v e r s i t y o f H a i l 1. Stacks top push (8)push (2)
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’
09-1 Queues and List-Based ADT Implementations Problem Set: PS3 due Wednesday, March 7 Wellesley College CS230 Lecture 09 Monday, February 26 Handout #18.
LECTURE 26: QUEUES CSC 212 – Data Structures. Using Stack.
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.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
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.
Foundations of Data Structures Practical Session #4 Recurrence ADT 08/04/2013Amihai Savir & Ilya Mirsky
CS102 – Data Structures Lists, Stacks, Queues, Trees & HashTables. David Davenport.
Question of the Day  Three people check into a hotel for which they pay the manager $30. The manager finds out the rate is $25 and gives $5 to the bellboy.
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.
Question of the Day  How can you change the position of 1 toothpick and leave the giraffe in exactly the same form, but possibly mirror-imaged or oriented.
1 Stacks (Continued) and Queues Array Stack Implementation Linked Stack Implementation The java.util.Stack class Queue Abstract Data Type (ADT) Queue ADT.
Queue and Tree in C Yang Zhengwei CSCI2100B Data Structures Tutorial 5 1.
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.
Question of the Day  How can you change the position of 1 toothpick and leave the giraffe in exactly the same form, but possibly mirror-imaged or oriented.
COSC 2P03 Week 21 Stacks – review A Last-In First-Out (LIFO) structure Basic Operations: –push : insert data item onto top of stack –pop : remove data.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 18 List ADT Animated Version.
3/3/20161 Stacks and Queues Introduction to Data Structures Ananda Gunawardena.
Queues CS 367 – Introduction to Data Structures. Queue A queue is a data structure that stores data in such a way that the last piece of data stored,
1 Queues (Continued) Queue ADT Linked queue implementation Array queue implementation Circular array queue implementation Deque Reading L&C , 9.3.
U n i v e r s i t y o f H a i l 1 ICS 202  2011 spring  Data Structures and Algorithms 
Queues.
Stacks – review A Last-In First-Out (LIFO) structure Basic Operations:
QueueStack CS1020.
Linked List Stacks, Linked List Queues, Dequeues
Chapter 15 Lists Objectives
Recap: Solution of Last Lecture Activity
Queues What is a queue? Queue Implementations: As Array
Topic 16 Queues Adapted from Mike Scott’s materials.
Stacks – review A Last-In First-Out (LIFO) structure Basic Operations:
Alyce Brady CS 470: Data Structures CS 510: Computer Algorithms
Lesson Objectives Aims
Lecture 5 Stacks King Fahd University of Petroleum & Minerals
Revised based on textbook author’s notes.
Queues A first-in, first-out or FIFO data structure.
Queues What is a Queue? Queue Implementations: As Array
Breadth First Search - A B C D E F G H I front FIFO Queue.
Introduction to Stacks
Introduction to Stacks
CSC 248 – fundamentals of Data structure
Queues What is a queue? Queue Implementations: As Array
Presentation transcript:

Queues What are queues? Queue Implementation Using Linked Lists. Applications of Queues.

What are queues? Queues are linear data structures in which we add elements to one end and remove them from the other end. Queues are called FIFO. Queue operations: Enqueue Dequeue

What are queues? enqueue(1); enqueue(5); dequeue(); RearFront Given the following Queue, how will it change when we apply the given operations?

Queue Interface Queue interface extends the Container interface. It inherits all the methods of the Container interface(getCount(), isEmpty(), isFull(), purge(), accept() and getEnumeration(). +Plus three mehods: getHead(), dequeue(), and enqueue()  It can be implemented with arrays or linked lists: 1 public interface Queue extends Container 2{ 3Object getHead(); 4void enqueue (Object object); 5Object dequeue (); 6} 7 public class QueueAsLinkedList extends AbstractContainer implements Queue 8{ 9protected LinkedList list; 10//... 11}

QueueAsLinkedList Constructor We create a linkedList object and put its reference in the list field of the QueueAsLinkedList class: public QueueAsLinkedList() { list = new LinkedList();

QueueAsLinkedList: purge() method nextDatumnextDatum 13 tail head nextDatumnextDatum 13 Count = 2 tail head Count = 0 public void purge() { list.purge(); count = 0; }

Methods of Queue Here are the three method of Queue: 1 public void enqueue (Object object) 2 { 3 list.append (object); 4 ++count; 5 } 6 public Object dequeue() 7 { 8 if (count ==0) 9 throw new ContainerEmptyException(); 10 Object result = list.getFirst(); 11 list.extract (result); 12 --count; 13 return result; 14 } 15 public Object getHead() 16 { 17 if (count == 0) 18 throw new ContainerEmptyException(); 19 return list.getFirst(); 20 }

Applecation There are many applications of queues, one application is breadth first traversal for trees. traversing a tree means, visiting the elements of the tree to do some computation on the values in the nodes. there are many ways of traversal,we will stuy next breadth first traversal. For more info. watch the animation on the CD since this ex. Isn’t our main issue & it’ll be determined later. A G D H BC EIF JK L