{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# 14Queue - ITI 1121 Introduction to Computing II Marcel...

This preview shows pages 1–8. Sign up to view the full content.

ITI 1121. Introduction to Computing II * Marcel Turcotte School of Information Technology and Engineering Version of March 2, 2011 Abstract Queues LinkedQueue * These lecture notes are meant to be looked at on a computer screen. Do not print them unless it is necessary.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Definitions A queue is a linear abstract data type such that insertions are made at one end, called the rear , and removals are made at the other end, called the front . Queues are sometimes called FIFOs: first-in first-out . enqueue() Queue dequeue() The two basic operations are: enqueue: adds an element to the rear of the queue; dequeue: removes and returns the element at the front of the queue. Software queues are similar to physical ones: queuing at the supermarket, at the bank, at cinemas, etc.
Applications Shared resources management (system programming): Access to the processor; Access to the peripherals such as disks and printers. Application programs: Simulations; Generating sequences of increasing length over a finite size alphabet; Navigating through a maze.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Example public class Test { public static void main( String[] args ) { Queue<Integer> queue = new QueueImplementation<Integer>(); for ( int i=0; i<10; i++ ) queue.enqueue( new Integer( i ) ); while ( ! queue.isEmpty() ) System.out.println( queue.dequeue() ); } } What does it print? 0, 1, 2, 3, 4, 5, 6, 7, 9
q = new Q(); q.enqueue( a ); q.enqueue( b ); q.enqueue( c ); q.dequeue( ); -> a q.dequeue( ); -> b q.enqueue( d ); q.dequeue( ); -> c q.dequeue( ); -> d Elements of a queue are processed in the same order as the they are inserted into the queue, here “a” was the first element to join the queue and it was the first to leave the queue: first-come first-serve .

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Implementations Just like stacks, there are two families of implementations: Linked elements; Array-based.