CC2203-Les10_-_ArrayQueue_Explanation-for-viewing-printing

CC2203-Les10_-_ArrayQueue_Explanation-for-viewing-printing...

Info iconThis preview shows pages 1–3. 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 Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ArrayQueue Explanation-1/3 ArrayQueue.java [4] [0] [1] [2] [3] A B C public void put(Object theElement) { if ((rear + 1) % queue.length == front) { Object [] newQueue = new Object [2 * queue.length]; int start = (front + 1) % queue.length; if (start < 2) // no wrap around System.arraycopy(queue, start, newQueue, 0, queue.length - 1); else { // queue wraps around System.arraycopy(queue, start, newQueue, 0, queue.length - start); System.arraycopy(queue, 0, newQueue, queue.length - start, rear + 1); } // switch to newQueue and set front and rear front = newQueue.length - 1; rear = queue.length - 2; // queue size is queue.length - 1 queue = newQueue; } // put theElement at the rear of the queue rear = (rear + 1) % queue.length; queue[rear] = theElement; } front rear D Case 1: put(“D”) queue ArrayQueue Explanation-2/3 ArrayQueue.java [4] [0] [1] [2] [3] A B C public void put(Object theElement) { if ((rear + 1) % queue.length == front) { Object [] newQueue = new Object [2 * queue.length];Object [] newQueue = new Object [2 * queue....
View Full Document

{[ snackBarMessage ]}

Page1 / 3

CC2203-Les10_-_ArrayQueue_Explanation-for-viewing-printing...

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

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