Chapter 6 Queue.

Slides:



Advertisements
Similar presentations
Transparency No. 1 Java Collection API : Built-in Data Structures for Java.
Advertisements

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)
Module R2 Overview. Process queues As processes enter the system and transition from state to state, they are stored queues. There may be many different.
Chapter 6 Queue. Learning Objectives ● Describe the behavior of a queue. ● Enumerate the primary operations supported by a queue. ● Learn about the UNIX.
1 Queues (5.2) CSE 2011 Winter May Announcements York Programming Contest Link also available from.
Data Structure Dr. Mohamed Khafagy.
Loops – While Loop Repetition Statements While Reading for this Lecture, L&L, 5.5.
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.
1 Foundations of Software Design Fall 2002 Marti Hearst Lecture 13: Queues and Vectors.
CSE 373 Data Structures and Algorithms Lecture 2: Queues.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
Lecture7: Queue Bohyung Han CSE, POSTECH CSED233: Data Structures (2014F)
Chapter 8 Queue I CS Data Structures I COSC2006 April 24, 2017
Stacks And Queues Chapter 18.
Chapter 8 Queues. © 2004 Pearson Addison-Wesley. All rights reserved 8-2 The Abstract Data Type Queue A queue –New items enter at the back, or rear, of.
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.
M180: Data Structures & Algorithms in Java Queues Arab Open University 1.
import java.util.Scanner; class myCode { public static void main(String[] args) { Scanner input= new Scanner(System.in); int num1; System.out.println(“Enter.
Chapter 4 ADTs Stack and Queue. 4-2 Formal ADT Specifications The Java interface construct lets us collect together method interfaces into a syntactic.
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.
Chapter 4 Unordered List.
Review Array Array Elements Accessing array elements
CSC111 Quick Revision.
Chapter 6 Queue.
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.
CC 215 Data Structures Queue ADT
Chapter 5 Ordered List.
Chapter 15 Lists Objectives
CSE 373: Data Structures and Algorithms
Stacks and Queues.
Queues Queues Queues.
Stack and Queue APURBO DATTA.
CSCE 3110 Data Structures & Algorithm Analysis
Repetition.
Something about Java Introduction to Problem Solving and Programming 1.
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
Principles of Computing – UFCFA3-30-1
Chapter 4 Unordered List.
Chapter 5 Ordered List.
Java Methods Stacks and Queues A & AB Object-Oriented Programming
Queues.
Topic 16 Queues "FISH queue: n.
Chapter 7 Stack.
Chapter 7 Stack.
An Introduction to Java – Part I, language basics
COMPUTER 2430 Object Oriented Programming and Data Structures I
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.
Queues: Implemented using Arrays
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,
Chapter 6 Queue.
Cs212: Data Structures Computer Science Department Lecture 7: Queues.
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 6 Queue.
Queues CSC212.
Stacks and Queues.
CE 221 Data Structures and Algorithms
17CS1102 DATA STRUCTURES © 2016 KL University – The contents of this presentation are an intellectual and copyrighted property of KL University. ALL RIGHTS.
CSC 248 – fundamentals of Data structure
CSC Java Programming, Spring, 2012
CSCS-200 Data Structure and Algorithms
Consider the following code:
Queues.
Data Structures & Programming
Presentation transcript:

Chapter 6 Queue

Learning Objectives Describe the behavior of a queue. Enumerate the primary operations supported by a queue. Learn about the UNIX print queue, the main commands that con be issued to it, and how these commands may be mapped to the operations of the queue data structure. Understand the public interface of a queue class in Java and the running times of its methods.

Learning Objectives Implement a print queue class in Java using the queue class. Study the implementation of the queue class, and the trade-offs involved in choosing between candidate storage components.

Queue Properties Queues Lines in which people “queue” up to be served, in a first come, first served manner. The typical computing environment queues are used to process requests for service on shared resources. Printer uses a first-come first-served policy. First served policy is also known as first in, first out, or FIFO for short.

Queue Properties

Queue Properties The FIFO policy is applicable only for entries that reach the front of the queue and are then removed. Entries may leave the queue without reaching the front.

Queue Properties

Floating-Front Design Approach

The Enqueue Operation

The Dequeue Operation

Simple Printer Queue command enqueues a print job. checks the status of the printer queue. First entry is currently being printed (active).

Simple Printer Queue Deletes the job that is currently active (being printed). Removes all the jobs.

A Queue Class

A Queue Class A queue can be considered a specialized (restricted) unordered list. An efficient implementation would maintain a direct reference to the rear and another to the front. Enqueue and dequeue can be implemented in O(1) time. Maintains a running count of the number of entries in the queue. The methods size and isEmpty can be implmented in O(1).

Queue Class Implementation Array list Front and rear are maintained to point to the respective ends of the queue.

Queue Class Implementation

Queue Class Implementation

Queue Class Implementation

Code for Printer Queue

Add new printer job by user Queue<String> printerQueue = new Queue<String>(); Scanner s = new Scanner(System.in); String fileName; System.out.println("Enter printer job file name"); fileName=s.next(); printerQueue.enqueue(fileName);

Remove active printer job fileName= printerQueue.dequeue(); System.out.println(fileName+" is deleted");

Remove all printer jobs printerQueue.clear();

Find number of printer jobs System.out.println("number of print jobs is: "+printerQueue.size());

Print active printer job System.out.println("active print job is: "+printerQueue.first());

Print printer queue status fileName = printerQueue.first(); while(fileName != null) { System.out.println(fileName); fileName = printerQueue.next(); }

The Whole program package printerapplication; import java.util.Scanner; public class PrinterApplication { public static void main(String[] args) { Queue<String> printerQueue = new Queue<String>(); boolean run = true; while(run) {System.out.println("To add new printer job press 1"); System.out.println("To remove active printer job press 2"); System.out.println("To remove all printer jobs press 3"); System.out.println("To find number of printer jobs press 4"); System.out.println("To print active printer job press 5"); System.out.println("To print printer queue status press 6"); System.out.println("To exit press 7"); Scanner s = new Scanner(System.in); String fileName; int choice = s.nextInt(); switch(choice) { case 1: // code to add new printer job then break case 2:// code to remove active printer job then break case 3: // code to remove all printer jobs then break case 4:// code to find number of printer jobs then break case 5:// code to print active printer job then break case 6:// code to print printer queue status then break case 7: run = false; break; }}}}