notes29

notes29 - Notes for the week of January 21, 2008 Queues...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Notes for the week of January 21, 2008 Queues Insertion and removal routines follow First In First Out principle. Elements are inserted at the rear of the queue and removed from the front. Array-Based Queue Also known as a "circular queue" Consists of an array of N elements, front and rear indexes, and a counter n with the number of elements in the queue. When rear==front, either the queue is empty or the queue is full. That is why we use "n" to know if the queue is full or empty, as well as the number of items in the queue. Circular queues are often used by device drivers to communicate with the device and the Operating System. QueueArray.java Class QueueArray { int N; //max size int n; //current number of elements in the queue int front; //index to the front of the queue int rear; //index to one after laster element in the queue Object array[]; //array that implements the queue Public QueueArray( int N ) { this.N = N; this.n = 0; this.front = 0; this.rear = 0; this.rear = 0; this.array = New Object[N]; } //add object to the queue
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

notes29 - Notes for the week of January 21, 2008 Queues...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online