Home
» write a algorithm to insert a value in circular queue from rear end
» Circular Queue algorithms
Monday, September 12, 2016
Circular Queue algorithms
Circular Queue algorithms:
This
algorithm is for inserting a value in circular queue:
Description:
Here QUEUE is an array
with Max locations. FRONT and REAR points to the front and rear elements of the QUEUE. ITEM is the value
to be inserted.
1) If( rear = Max-1 and front == 0 ) or (REAR +1
=FRONT) Then
2) Print ” Queue if full ”
3) Else
4) If (REAR == -1) Then [Check if QUEUE is empty]
1. Set FRONT
= 0
2. Set REAR
= 0
5)
Else If (REAR == Max-1) Then [If REAR reaches end if QUEUE]
6) Set REAR = 0
7) Else
8)
Set REAR = REAR + 1 [Increment REAR by 1]
[End
of Step 4 If]
9) Set QUEUE[REAR] = ITEM
10)
Print “ITEM inserted”
[End of Step 1 If]
11) Exit
|
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment