Software Development

Easy methods to handle Full Round Queue occasion?


  

#embrace <bits/stdc++.h>

utilizing namespace std;

  

class Queue

    

    int rear, entrance;

  

    

    int measurement;

    int* arr;

  

public:

    Queue(int s)

    

        entrance = rear = -1;

        measurement = s;

        arr = new int[s];

    

  

    void enQueue(int worth);

    int deQueue();

    void displayQueue();

;

  

void Queue::enQueue(int worth)

(rear == (entrance - 1) % (measurement - 1)))

        printf("nQueue is Full");

        return;

    

  

    

    else if (entrance == -1)

        entrance = rear = 0;

        arr[rear] = worth;

    

  

    else if (rear == measurement - 1 && entrance != 0)

        rear = 0;

        arr[rear] = worth;

    

  

    else

        rear++;

        arr[rear] = worth;

    

  

int Queue::deQueue()

    if (entrance == -1)

        printf("nQueue is Empty");

        return INT_MIN;

    

  

    int knowledge = arr[front];

    arr[front] = -1;

    if (entrance == rear)

        entrance = -1;

        rear = -1;

    

    else if (entrance == measurement - 1)

        entrance = 0;

    else

        entrance++;

  

    return knowledge;

  

void Queue::displayQueue()

    if (entrance == -1)

        printf("nQueue is Empty");

        return;

    

    printf("nElements in Round Queue are: ");

    if (rear >= entrance)

        for (int i = entrance; i <= rear; i++)

            printf("%d ", arr[i]);

    

    else

        for (int i = entrance; i < measurement; i++)

            printf("%d ", arr[i]);

  

        for (int i = 0; i <= rear; i++)

            printf("%d ", arr[i]);

    

  

int essential()

    Queue q(5);

  

    

    q.enQueue(14);

    q.enQueue(22);

    q.enQueue(13);

    q.enQueue(-6);

  

    

    q.displayQueue();

  

    

    printf("nDeleted worth = %d", q.deQueue());

    printf("nDeleted worth = %d", q.deQueue());

  

    q.displayQueue();

  

    q.enQueue(9);

    q.enQueue(20);

    q.enQueue(5);

  

    q.displayQueue();

  

    q.enQueue(20);

  

    return 0;

What's your reaction?

Leave A Reply

Your email address will not be published. Required fields are marked *