Introduction
In this lab you will modify existing code and write new code which implements queues as arrays. This lab will be completed individually rather than in groups.
- Due Friday, Mar 5, 2010
Instructions
- Lafore Programming Task 4.1 (slightly modified) "Write a method displayQueue() for the Queue class in the queue.java program (Listing 4.4) that displays the contents of the queue. Note that this does not mean simply displaying the contents of the underlying array. You should show the queue contents from the first item inserted to the last, without indicating to the viewer whether the sequence is broken by wrapping around the end of the array. Be careful that your displayQueue() method works properly when the queue has one item or no items, and no matter where front and rear are."
/* * Display queue from front to rear */ public void displayQueue(); /* * Display queue from front to rear. * * @param showArray when true, also display * the underlying array, marking front and rear. */ public void displayQueue(boolean showArray);
Allow displayQueue(...) to take a single boolean argument. When passed an argument with the value true, displayQueue(...) should display BOTH the queue (as described above) AND the underlying array. When false, or when no argument is supplied, displayQueue(...) displays ONLY the queue.
When displaying the underlying array, indicate the front and the rear of the queue. {Use your lab report to explain any choices, decisions, limitations, etc. The basic requirement is that front and rear be indicated in some way -- how elegant the indication will determine additional points.}
Develop a tester class that demonstrates the functionality of your displayQueue() methods. Make sure you show the range of possible situations (e.g., empty, wrapped...). Include a screenshot or copied output of a successful run, along with the code.
- Lafore Programming Task 4.2 from the text (p. 176) See page 143 in the text for a brief description of a double-ended queue or deque (pronounced "deck" -- note also the correct spelling is deque rather than dequeue). Create your own class Deque based on the discussion of deques in this chapter. It should include insertLeft(), insertRight(), removeLeft(), removeRight(), isEmpty(), and isFull() methods. It should support wrap-around at the end of the array, as queues do.
As in task 1, include a method displayDeque(...) which displays either the deque alone (by default), or the deque along with its underlying array representation (when called with an appropriate boolean argument).
Develop a tester class that demonstrates the functionality of your deQue. Make sure you show the range of possible situations (e.g., empty, wrapped...). Include a screenshot or copied output of a successful run, along with the code.
- Include a lab report with your submission, describing your development process, any design decisions made along the way, format/method of input & output, and limitations on your code.
Due date & submission
- Submit your assignment as a single .zip archive file titled LAB41_lastname.zip. It should include working, documented java code for both parts of the lab, as well as the lab report.
- Submit via Sakai.
