### Queue: Linear Queue Implementation

A Queue is a linear, ordered collection of items or data structure in which the operations are performed in First In First Out fashion . Meaning, it is always the first item to be put into the queue, and first item is to be removed first .

The main difference between stack and queue is in removing items. In stack, we remove the most recently added but in case of queue, we remove the least recently added .

A good example of queue is any queue of people waiting for resources, i.e. The first person in the queue is served first.

In Linear Queue, the arrangement of items in queue is linear.

#### Algorithm For Insertion

Initially,

``````
front = 0
rear = -1``````

1. Start

2 .Check if queue if full or not

``````if(queue.full())
print("queue is full")
else
process step 3``````

3. i. Increase rear by 1
ii. Read data and store at rear position of array

4. Stop

#### Algorithm For Deletion

a. Without Shift

1. Start

2 .Check if queue if empty or not

``````if(queue.empty())
print("queue is empty")
else
process step 3``````

3. Increase front by 1

4. Stop

b. With Shift

1. Start

2 .Check if queue if empty or not

``````if(queue.empty())
print("queue is empty")
else
process step 3``````

3. i. Shift all elements towards front by 1 position
ii. Decrease rear by 1

4. Stop

#### Problems With Linear Queue

Both the rear and front indices are increase but never decreased. As items are removed from the queue, the storage space at the beginning of the array is discarded and never used again. Wastage of the space is the main problem with linear queue.

#### Now What’s Next ?

Queue: Template Implementation Of Dynamic Linear Queue Using C++