Question

In: Computer Science

Why a circular queue is more benefiting than a single dimension array queue? How to do...

Why a circular queue is more benefiting than a single dimension array queue? How to do indexing in a circular queue? (explain briefly in java)

Solutions

Expert Solution

Why a circular queue is more benefiting than a single dimension array queue?

One of the advantages of the circular queue is that we can utilize the spaces in front of the queue. In an single dimension array queue, when the queue turns out to be full, we can't embed the following component regardless of whether there is a space in front the queue. However, utilizing the circular queue, we can utilize the space to store new elements.

How to do indexing in a circular queue?

Front gets the front element in the queue, rear gets the last element in the queue.

enQueue(value) is the capacity is utilized to embed a component into the circular queue. In a circular queue, the new component is constantly embedded at Rear position.

Steps include in enQueue are:

Check whether queue is full or not – Check ((rear == SIZE-1 && front == 0) || (rear == front-1)).

In the event that it is full, at that point show Queue is full. On the off chance that line isn't full, at that point, check if (rear == SIZE – 1 && front != 0) on the off chance that it is valid, at that point set rear=0 and insert element.

deQueue() is used utilized to erase a component from the circular queue. In a circular queue, the component is constantly erased from front position.

Steps include in deQueue are

Check whether line is Empty methods check (front==-1).

In the event that it is unfilled, at that point show Queue is vacant. On the off chance that line isn't unfilled, at that point stage 3

Check in the event that (front==rear) on the off chance that it is valid, at that point set front=rear= - 1 else check on the off chance that (front==size-1), on the off chance that it is valid, at that point set front=0 and return the element.


Related Solutions

JAVA: Implement a Queue ADT using a circular array with 5 string elements. Create a Queue...
JAVA: Implement a Queue ADT using a circular array with 5 string elements. Create a Queue object and try various operations below. Queue myQueue = new Queue(); myQueue.enqueue(“CPS 123”); myQueue.enqueue(“CPS 223”); myQueue.enqueue(“CPS 323”); myQueue.dequeue(); myQueue.enqueue(“CPS 113”); myQueue.enqueue(“CPS 153”); string course = myQueue.front(); // course should be CPS 223 size = myQueue.size(); // size should be 4 // output course and size
Do you consider political dimension to have a greater impact than economic dimension to organizational change?
Do you consider political dimension to have a greater impact than economic dimension to organizational change?
Discussion Why is migration more difficult to measure than fertility and mortality? How do changes in...
Discussion Why is migration more difficult to measure than fertility and mortality? How do changes in fertility, mortality, and migration affect population composition?
Why do some people crave drugs more than others?
Why do some people crave drugs more than others?
Why are banks being more regulated than your normal business would be? How do we regulate...
Why are banks being more regulated than your normal business would be? How do we regulate them?
how a single gene can result in more than one RNA product? and What is the...
how a single gene can result in more than one RNA product? and What is the GU-AG rule and how does it contribute to this process?
Should the government regulate derivatives more than they do now? If so, why?
Should the government regulate derivatives more than they do now? If so, why?
-What is the benefit of diversification and how do mutual funds do this more effective than...
-What is the benefit of diversification and how do mutual funds do this more effective than an ordinary investor?
Why are aldehydes usually more reactive than ketones? Why are ketones more reactive than esters, and...
Why are aldehydes usually more reactive than ketones? Why are ketones more reactive than esters, and ester more reactive than amides? Please help explain with the help of steric, indcutive and resonance effects. Show an example for each class of compounds please. Thank you!
Explain why dyes attach to natural fibers more readily than synthetic fibers. How do the structures relate?
Explain why dyes attach to natural fibers more readily than synthetic fibers. How do the structures relate?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT