
please wait
|
|
|
|
Queue empty : true // 1st call to is Empty. Queue contents : 2 Queue contents : 2 4 6 8 Front of queue : 2 Queue empty : false // 2nd call to is Empty. Dequeing : 2 Dequeing : 4 Dequeing : 6 Queue contents : 8 Front of queue : 8 Queue empty : false // 3rd call to is Empty. Dequeing : 8 Queue is empty Front of queue : -1 Queue empty : true // 4th call to is Empty. |
|
|
Queue empty : true Queue contents : 2 Queue contents : 2 4 6 8 Front of queue : 2 Queue empty : false Dequeing: 2 Dequeing: 4 Dequeing: 6 Queue contents : 8 Front of queue : 8 Queue empty : false Dequeing: 8 Front of queue : Queue is empty -1 Queue empty : true |
some things: - in enqueue() you consider rearQ == size - 1 as full, however size-1 is a valid index for an array - in dequeue() you say frontQ == rearQ is an empty queue, however you still dequeue that element - ¿does rearQ points to the last element or one past the last element? - you could wrap around the array in order to use the space available after a dequeue operation - ¿why enqueue() and dequeue() don't make use of isEmpty() and instead define their own empty criteria? |