{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

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

ITI 1121. Introduction to Computing II * Marcel Turcotte School of Information Technology and Engineering Version of March 8, 2011 Abstract Queues ArrayQueue * 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.
ADT public interface Queue<E> { public abstract boolean isEmpty(); public abstract void enqueue( E o ); public abstract E dequeue(); }

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

View Full Document
Using an array public class ArrayQueue<E> implements Queue<E> { private E[] elems; public boolean isEmpty() { ... } public void enqueue( E o ) { ... } public E dequeue() { ... } }
Array implementation of a queue Implementation 1: Let’s set the front of the queue to a fix location, say 0, and use an instance variable to indicate the location of the rear element. 6 7 0 1 2 3 4 5 8 9 queue rear = 4 a b c d e Contrary to the array-based implementation of a stack, using an array to implement a queue will create some problems, which we will circumvent, of course!

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

View Full Document
Array implementation of a queue public class ArrayQueue<E> implements Queue<E> { private E[] elems; private int rear; public boolean isEmpty() { ... } public void enqueue( E o ) { ... } public E dequeue() { ... } }
Remarks Just like stacks, rear can be made to designate the first free location (instead of the element itself); a queue could be implemented in the upper part of the array. Without effects on the efficiency.

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

View Full Document
Insertion (enqueue) Inserting an element into a queue, when the front location is fixed, is similar to adding an element onto a stack.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 39

15Queue - ITI 1121 Introduction to Computing II Marcel...

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

View Full Document
Ask a homework question - tutors are online