Lecture 14 - ECE 2574 Introduction to Data Structures and...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ECE 2574 Introduction to Data Structures and Algorithms Lecture 14: Queues Reading: Chapter 7 Chris Wyatt Electrical and Computer Engineering and School of Biomedical Engineering and Sciences Virginia Tech Announcement I am removing my Wednesday office hour. They are now: Monday 4-5 Thursday 1-2 Other times by appointment Monday Schedule Queue ADT Linked List Implementation of queue Survey (Lisa Darlington, last 20 minutes) The Queue ADT is a list in which the first item inserted is the first item retrieved. Unlike the stack, a queue is a "fair" system. Example: the first person in line is the first person to be served. Queues have a front and a rear (also called the back). rear front The Queue ADT Basic Queue operations // Create an empty queue +createQueue() // Destroy a queue +destroyQueue() //Determine if a queue is empty //Precondition: None //Postcondition: returns true is the queue is empty, else false +isEmpty(): boolean Inserting into a queue is called an enqueue. // adds new item to the queue //Precondition: valid queue //Postcondition: queue is 1 larger returns true/false if succeeds/fails +enqueue(in newItem:QueueItemType): boolean Removing an item from a Queue is called a dequeue. // remove the front item in the queue //Precondition: valid queue //Postcondition: queue is 1 smaller, front item removed returns true/false if succeeds/fails +dequeue(): boolean // retrieve and remove the front item in the queue //Precondition: valid queue //Postcondition: queue is 1 smaller, front item removed returns true/false if succeeds/fails +dequeue(out stackTop:QueueItemType): boolean Retrieving from the Queue without removing the item, i.e. retrieving the front item. // retrieves the item currently at the queue front. //Precondition: valid queue //Postcondition: places queue front in queueFront output returns true/false if succeeds/fails +getFront(out queueFront:QueueItemType): boolean Queue Example: printer buffers In class exercise: After each of the following operations, what are the contents of the queue ? 1. queue q; 2. q.enqueue(41); 3. q.enqueue(12); 4. q.enqueue(8); 5. q.dequeue(); 6. q.enqueue(36); 7. q.dequeue(); 8. q.dequeue(); Linked List Implementation of the Queue (see QueueP.h and QueueP.cpp) Download QueueP.zip From Black-Board under Course Documents Linked List implementation of the Queue ADT. Inserting at the rear (back) of the queue. Removing from the front of the queue. In class exercise Write a set of tests in main.cxx that test the Queue class. Warmup Due before noon on Wednesday. ...
View Full Document

This note was uploaded on 04/01/2008 for the course ECE 2574 taught by Professor Chuang during the Fall '08 term at Virginia Tech.

Ask a homework question - tutors are online