Skip to content

Latest commit

 

History

History
76 lines (66 loc) · 1.54 KB

Queue.md

File metadata and controls

76 lines (66 loc) · 1.54 KB

Queue

A queue is a list with the restriction that you can insert at the front of the list and you can delete at the end of the list.

Linear Queue Array

typedef struct{
    int que[size];

    int front;
    int rear;
} Queue;

que

The actual array of Queue.

front

The front of the Queue, this is where you ### [EnQueue] in the Queue. front starts at index 0.

rear

The rear of the Queue, this is where you ### [DeQueue] in the Queue. rear starts at index -1.

Queue

Queue Operataions

EnQueue

The function increases rear and inserts a value in that index.

void EnQueue(Queue* queue, int val){
    queue->rear += 1;
    queue->que[queue->rear] = val;
}

enqueue_gif

DeQueue

The function saves front in data; increments front; and returns data.

int DeQueue(Queue* queue){
    int data queue->que[queue->front];
    queue->front += 1;
    return data;
}

dequeue_gif

IsFull

The function check if the Queue is full by checking if rear is equal to size.

bool isFull(int rear){
    bool full = false;
    if(rear == size-1)
        full = true;
    return true;
}

IsEmpty

The function check if the Queue is empty by checking if front is greater than rear.

bool isEmpty(int rear){
    bool empty = false;
    if(rear+1 == front)
        empty = true;
    return true;
}

Reference

Circular Version

Circular Queue

Linked List Version

Queue linked List

Back To Main