Question: JAVA (Data structure) Stack and queque 7) What are the values for indexOfFront, indexOfRear and size of queue after the last operation is executed for
"JAVA (Data structure) Stack and queque
7) What are the values for indexOfFront, indexOfRear and size of queue after the last operation is executed for a circular queue.
(you must provide three values)
ArrayQueue
array size is 5. (there are 5 slots in the array)
operation indexOfFront indexOfRear size of queue
myQ.enqueue(one);
myQ.enqueue(two);
myQ.enqueue(three);
myQ.dequeue( );
myQ.dequeue( ); myQ.dequeue( );
myQ.enqueue(four);
myQ.enqueue(five);
myQ.enqueue(six);
myQ.enqueue(seven);
myQ.dequeue( );
myQ.enqueue(eight);
myQ.dequeue( );
8) State why implementing a queue using a "circular array" is more efficient that having the index of the front fixed at 0.
9) What is the principle difference in behavior between a stack and a queue?
| a stack is used to reverse order of the data whereas a queue preserves order |
| access to the data in a stack can be done in any order, but access to the data in a queue is from the front of the queue only |
| there is no difference in the access to the data in a stack vs a queue |
| a stack is used to preserve the order of the data and a queue is used to reverse the order of the data |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
