Lect12_array_queue0

Lect12_array_queue0 - ITI 1121. Introduction to Computing...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: ITI 1121. Introduction to Computing II * Marcel Turcotte School of Information Technology and Engineering Version of March 1, 2010 Abstract Queues ArrayQueue * These lecture notes are meant to be looked at on a computer screen. Do not print them unless it is necessary. 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(); } 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: Lets 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 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! 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....
View Full Document

This note was uploaded on 01/06/2011 for the course ITI 1121 taught by Professor Samaan during the Spring '10 term at University of Ottawa.

Page1 / 39

Lect12_array_queue0 - ITI 1121. Introduction to Computing...

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

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