Unit03B

# Unit03B - More Linear Data Structures Queues Queues 3B 1 2...

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

1 More Linear Data Structures Queues 3B 2 Queues 3 Queue Operations public interface FIFOQueue<E> { public void enqueue(E element); // Insert element at rear of queue public boolean isEmpty(); // Is the queue empty? public E dequeue(); // Remove element from front of queue public E peek(); // Examine element at front of queue } 4 Queues using an array 0 1 2 3 4 5 6 7 8 9 10 11 Store the elements of the queue from front to rear in order in the array. What happens if we store the front of the queue always in position 0? FRONT REAR 5 Queues using an array 0 1 2 3 4 5 6 7 8 9 10 11 Store the elements of the queue from front to rear in order in the array. What happens if we store the rear of the queue always in last position in the array? FRONT REAR 6 Queues using a “circular” array 0 1 2 3 4 5 6 7 8 9 10 11 Allow the queue to “wrap around” from the last cell of the array back to the first cell so shifting is not necessary. If the array is full, we can reallocate the array and copy the queue data into the new array starting at position 0 again. FRONT

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

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

## This note was uploaded on 12/19/2009 for the course CS 121 taught by Professor Reid-miller during the Spring '09 term at Carnegie Mellon.

### Page1 / 4

Unit03B - More Linear Data Structures Queues Queues 3B 1 2...

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

View Full Document
Ask a homework question - tutors are online