ARRAY IMPLEMENTATION OF CIRCULAR QUEUE
Aim
To write a c
program using arrays for implementing circular queue data structure.
Algorithm
Step 1: [Include
All Header Files Required]
Step
2: [Define the array size as 5 and declare front and rear pointers]
Step
3: Declare the functions isEmpty() , isFull(), enqueue(), size(),dequeue(),
peek() and
view()]
Step
4: [Call the functions]
Choice
:1 CALL enqueue()
Choice
:2 CALL deenqueue()
Choice :3 CALL peek()
Choice :4 CALL size()
Choice :5 CALL view()
Algorithm for isEmpty( )
Step 1: [Check for underflow]
RETURN -1
Step 2: Else RETURN 0
[Finish the
process]
Algorithm for isFull( )
Step 1: [Check for overflow]
RETURN -1
Step 2: Else RETURN 0
[Finish the
process]
Algorithm for Enqueue( )
STEP 1:
If[front= =rear]
Initialize
front=rear=0
STEP 2: else
rear=(rear+1)% qsize
Set queue[rear] =value
[return]
Algorithm for Dequeue( )
STEP 1: If[front
= =rear]
1.1: temp=queue[front]
1.2: Initialize front=rear=-1
STEP 2:else
2.1:
front=(front+1)% qsize
[return]
Algorithm for Peek( )
STEP 1:If
[front= =rear]
STEP 1.1:
temp=queue[front]
[return]
Algorithm for Size( )
STEP 1:If
[front= =rear]
1.1: Set f=front
1.2: Set count=1
STEP 2: If
[front!=rear]
2.1: front=(front+1)%qsize
2.2: set count=count+1
[return]
Algorithm for View( )
STEP 1: If
[front = =rear]
Write (“Queue is empty”)
STEP 2: else
[display elements]
Coding: