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

    ROCKTHEAGESLLC

    • 3552 Words
    • 41 Pages

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

    • 3552 Words
    • 41 Pages
    Good Essays
  • Satisfactory Essays

    NT1230 Lab 10

    • 1546 Words
    • 8 Pages

    6. In the Instances of selected object list, select 0, and then click Add. The Queue Length counter appears in the Added counters list.…

    • 1546 Words
    • 8 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Lab 6

    • 690 Words
    • 3 Pages

    1. Run your model. Compare the queue statistics of the 3 processes with those obtained for Part C in the previous Lab. How have they changed and what conclusions can you draw? (Note the sums of all capacities for both cases are equivalent – 12 in each).…

    • 690 Words
    • 3 Pages
    Satisfactory 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

    Littlefield Case Study

    • 875 Words
    • 4 Pages

    Before the simulation started, our team created a trend forecast, using the first 50 days of data, showing us that the bottleneck station was at Station 1. On day 50 of the simulation, my team, 1teamsf, decided to buy a second machine to sustain our $1,000 revenue per day and met our quoted lead time for producing and shipping receivers. On day 97, we changed Station 2’s scheduling rule to priority step 2. We noticed that the bottleneck was not just at station 1, but at all stations, and that buying a new machine would not be the right choice to make, but rather, changing the way in which the station’s processing is queued would be the better option. By doing this, we could produce all incoming kits with a priority enabling an even flow of kits to Station 3. At day 97, our team ranked first in the overall standing, and wanted to try to maintain this standing for the rest of the simulation.…

    • 875 Words
    • 4 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
  • 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
  • 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
  • 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
  • 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

    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