Difference between revisions of "CircularQueue Assignment"

From WLCS
(New page: * Using your Queue class, copy it and rename it CircularQueue.java. You will then make the following changes to create a wrap-around circular queue. First, add a new attribute named size ...)
 
Line 1: Line 1:
 +
* [[Media:CircularQueueMain.java]]
 +
* Be sure to change all the CircularQueue instances to Queue. What you should find is that your Queue does not work.  Why?
 +
* Change all the Queue instances back to CircularQueue.  We shall create a new Queue class called CircularQueue:
 +
  
 
* Using your Queue class, copy it and rename it CircularQueue.java. You will then make the following changes to create a wrap-around circular queue. First, add a new attribute named size that keeps track of the number of elements added to the queue
 
* Using your Queue class, copy it and rename it CircularQueue.java. You will then make the following changes to create a wrap-around circular queue. First, add a new attribute named size that keeps track of the number of elements added to the queue

Revision as of 10:18, 13 October 2008

  • Media:CircularQueueMain.java
  • Be sure to change all the CircularQueue instances to Queue. What you should find is that your Queue does not work. Why?
  • Change all the Queue instances back to CircularQueue. We shall create a new Queue class called CircularQueue:


  • Using your Queue class, copy it and rename it CircularQueue.java. You will then make the following changes to create a wrap-around circular queue. First, add a new attribute named size that keeps track of the number of elements added to the queue
  • Fix the add() method so that the tail wraps around back to index 0 if it reaches the end. REMEMBER, you must first check to see if the queue is full or not because you cannot wrap around if the queue is full. You should also increase size by one.
  • Fix the remove() method so that the head wraps around back to index 0 if it reaches the end. You should also decreasesize by one. Don't forget to check if the list is empty.
  • Fix the isEmpty() method so that it uses the size attribute in the if-statement condition
  • Fix the isFull() method so that it uses the size attribute in the if-statement condition
  • Fix the print() method so that the entire queue is printed from head to tail
  • You may test your queue using Media:CircularQueueMain.java