Preview

Circular Queue

Good Essays
Open Document
Open Document
1571 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Circular Queue
It's going to be a static implementation of queues and good for limited elements to be handled, as you know array size has to be pre-defined and can't be changed dynamically. Here, every time you insert a new element in the queue you'll check for the queue 'overflow' condition as we are using a static array to implement the queue.
Here, I'll take rear as -1 and front as 0 when the Queue is empty.
Algorithm:-
Step-1: Increment the 'rear' by 1
Step-2: Check for the 'queue overflow' condition. If queue not overflowing then go to step-3 else say "queue overflow" and quit
Step-3: Put the new element at the position pointed by 'rear'
C implementation:- static int queue[max]; int front = 0, rear = -1;
..
.. insert(int new)
{
rear = rear + 1; if(rear < max) queue[rear] = new; else printf("Queue overflow");
}
When an element leaves the queue the 'front' gets incremented by one. Every time before deletion we'll check for the 'queue empty' condition. If the queue is not empty, put a NULL value at the position pointed by 'front' and increment the value of 'front' by 1.
Algorithm:-
Step-1: If the queue is empty then quit else go to step-2
Step-2: Put a NULL value at the position pointed by 'front'. Increment the 'front' by 1.
C implementation:- static int queue[max]; int front = 0, rear = -1; /*when the queue is empty*/
..
.. int delete( )
{
int del_val =0; /*holds the deleted value*/ if(front > rear) printf("Queue empty"); else { del_val = queue[front]; queue[front] = NULL; /*this represents that the element has been deleted*/ front = front + 1; } return(del_val); }

Haven't you realised that the regular, static queues we saw have a very big drawback that once the queue is FULL, even though we delete few elements from the "front" and relieve some occupied space, we are not able to add anymore elements, as the "rear" has already reached the Queue's rear most position. The solution lies in

You May Also Find These Documents Helpful

  • Good Essays

    WGU JGT Task #1

    • 1134 Words
    • 5 Pages

    Line balancing is the methodology of equalizing the amount of work at each workstation. The principles of line balancing are needed to improve the efficiency of the production of the boots at each station. Jobs are broken down into the smallest work elements so that they can be performed by more than one worker at a single workstation. Since there is an order in which the boot construction is performed, there are precedence requirements that place restrictions on the sequence of production. (http://wps.prenhall.com/wps/media/objects)…

    • 1134 Words
    • 5 Pages
    Good Essays
  • Good Essays

    Nt1330 Unit 9 Final Paper

    • 1263 Words
    • 6 Pages

    Assuming 5 MDs on duty at an average (each with a service rate of 3.1 patients per hour) and that all patients (143 per day) see an MD, calculate the effect of a 4% increase in the arrival rate on the expected wait time in queue: Wq (use Queuing Formulas, assume uniform arrival across 10 working hours per day, note that it’s a multiple server system drawing from a single line – M/M/S). Comment on this…

    • 1263 Words
    • 6 Pages
    Good Essays
  • Good Essays

    ROCKTHEAGESLLC

    • 3552 Words
    • 41 Pages

    (see instructions) . . . . . . . . . . . . . . . . . . . . . . 1d…

    • 3552 Words
    • 41 Pages
    Good Essays
  • Satisfactory Essays

    PT1420 Unit 8 Lab 8

    • 365 Words
    • 2 Pages

    Incrementing by Values Other than 1, page 190): Display numbers starting at 0 through 10 by increments of 2. 0,2,4,6,8,10…

    • 365 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    B Max Cell Book Report

    • 396 Words
    • 2 Pages

    On 5-19-2017 at approximately 2230 hours, you (Officer Nathan) became aware that inmates were being threatened. These inmates were locked in a “B” Max cell together and all of the other inmates in “B” Max were also locked in their cells. I (Sgt Webber) directed you to handcuff an inmate and bring that inmate to the Booking area for questioning; you complied. After the inmate was questioned, I specifically directed you to place that inmate in his cell. You departed the area with a handcuffed inmate and a direct order.…

    • 396 Words
    • 2 Pages
    Good Essays
  • Satisfactory Essays

    Brs Mdm3 Tif Ch09

    • 2979 Words
    • 16 Pages

    5) In a drive-in fast food restaurant, customers form a single lane, place their order and pay their bill at one window, and then pick up their food at a second window. This queuing configuration is referred to as:…

    • 2979 Words
    • 16 Pages
    Satisfactory Essays
  • Powerful Essays

    Simul8 Report

    • 1272 Words
    • 6 Pages

    Figure 1 depicts the model used for the simulation, where the two types of calls enter the system through the two entry points - type 1 and type 2. They are then sorted and routed out to their respective queues through labels named ‘type’. Type 1 customers are served by either agent 1 or agent 3 (generalist), depending on availability. Similarly, type 2 customers are served by agent 2 or agent 3, after which the customers leave the system by their respective exit points.…

    • 1272 Words
    • 6 Pages
    Powerful Essays
  • Good Essays

    Conflicts are often started by the utilization of labels. By labeling a certain person or calling them a name it is essentially grouping them into a larger idea or force. In the film Empire of the Sun directed by Steven Spielberg and the novel When the Emperor Was Divine by Julie Otsuka the main characters struggle with identifying which side of World War II they are supposed to be aligned with. The protagonists from both of the works experience a moment where the line between good and bad is extremely thin. Both Jamie and the family are forced to question their allegiances in World War II.…

    • 798 Words
    • 4 Pages
    Good Essays
  • Satisfactory Essays

    Vonkel Case

    • 566 Words
    • 3 Pages

    Ans: By using Just-in-time inventory method Vonkel can effectively manage their inventory. The aim JIT is to reducing buffer inventory to Zero.…

    • 566 Words
    • 3 Pages
    Satisfactory Essays
  • Good Essays

    C++ Midterm

    • 2831 Words
    • 12 Pages

    What is the value inside the "value" variable at the end of the given code snippet?…

    • 2831 Words
    • 12 Pages
    Good Essays
  • Powerful Essays

    Best Case Scenarios

    • 442 Words
    • 2 Pages

    c1n + c2(n-1) + c3n^2 + c4(n^2-1) + c5(0) + c6(n^2-1) + c7(0) + c8(0) + c9(0) =…

    • 442 Words
    • 2 Pages
    Powerful Essays
  • Powerful Essays

    A rope divider is used at all times that guides customers to the order point. I visit Chipotle on a regular basis during peak times and I find the system adequate in moving customers through the process. Employees appear well trained in preparing the selections quickly without error. A sign should be placed to direct the pick-up of phone, fax, or I-Phone orders.…

    • 1881 Words
    • 8 Pages
    Powerful Essays
  • Good Essays

    Producer vs Consumer

    • 590 Words
    • 3 Pages

    The solution calls for the producer to sleep, or stop producing if it is full, whereupon the next item removed by the consumer will wake up the sleeping producer to force it to push another item in the buffer. The same method applies to when the buffer is empty; as such the consumer shouldn’t be consuming anything and should go to sleep until the producer deposits a new item into the buffer. The solution provided uses semaphores, enabling inter-process communication.…

    • 590 Words
    • 3 Pages
    Good Essays
  • Satisfactory Essays

    Flame and Air Adjustment

    • 357 Words
    • 2 Pages

    1. Place all three riders in the zero position, and set the pointer on zero.…

    • 357 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Mid Term 1 Solution

    • 534 Words
    • 3 Pages

    Answer: In this problem we are more interested in finding the median instead of the minimum/maximum element. The ⌊ n ⌋th element in a min/max heap is not the median. 2 In this case, we should develop a new type of heap to adapt this problem.…

    • 534 Words
    • 3 Pages
    Satisfactory Essays