What is Queue?
- Queue is a liner data structure.it means elements in this data structure have a unique predecessor and a unique successor.
- Queue follows First In First Out (FIFO) technique.
- Initial value of Rear and Front is -1 which is known as centennial value.
- When new Element is inserted in a Queue then Rear is Incremented by one and this term is known as Enqueue.
- When an element is deleted from a Queue then Front is Incremented by one and this term is known as Dequeue.
- When there is no space for inserting new element and we try to insert then what situations comes known as Queue overflow i.e no space for insertion.
- When there is no element in Queue and we try to delete then what situations comes known as Queue underflow i.e no element for deletion.
- When Queue is full then Rear will be at size-1.
- Queue can be represented or implemented in two ways.
- Queue as an array
- Queue as a linked list
Types of Queue
- Linear Queue
- Circular Queue
- Priority Queue
Linear Queue
Algorithm: Insert Operation on Queue
Step 1: If Rear=Max-1
Print “Overflow : Queue is full” and Exit
End If
Step 2: If Front=-1
Set Front =0
End If
Step 3: Rear=Rear+1
Step 4: Queue[Rear]=Element
Step 5: End
Algorithm: Delete Operation on Queue
Step 1: If Front=-1
Print “Underflow: Queue is empty” and Exit
End if
Step 2: Set Del_element=Queue[Front]
Step 3: If Front=Rear
Set Front=Rear=-1
Else
Front=Front+1
End If
Step 4: Return Del_Element
Step 5: End