0% found this document useful (0 votes)
21 views

Write The Pseudo Code For The Algorithms For

The pseudo code provides algorithms for: 1) Inserting an element at the rear of a circular queue by checking if the queue is full, incrementing the rear pointer, and adding the element. 2) Deleting and returning the last element of a circular queue by retrieving the element at the rear pointer, incrementing the front pointer if needed, and returning the element.

Uploaded by

Mohammed Jeelan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Write The Pseudo Code For The Algorithms For

The pseudo code provides algorithms for: 1) Inserting an element at the rear of a circular queue by checking if the queue is full, incrementing the rear pointer, and adding the element. 2) Deleting and returning the last element of a circular queue by retrieving the element at the rear pointer, incrementing the front pointer if needed, and returning the element.

Uploaded by

Mohammed Jeelan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Q.5.

Write the pseudo code for the Algorithms for

I)

Inserting a given element at the rear of Circular Queue

Step-1: Get value to be inserted into X.


Step-2: Check If (front=0 and rear=size of queue) or front=rear+1 Then
Print queue is full
Break execution.
Step-3: Check If front=0 Then
Set rear=1 and front=1
Else if rear=size of queue Then
Set rear = 1
Else
Set rear=rear+1
End if
Step-4: Set Circular_Queue[rear]=X.
Step-5: Finish.

II)

Deleting and returning the last element from a Circular Queue.

Step-1: Check If front = 0 Then


Print Queue is empty
Break execution.
Step-2: Set X = Circular_Queue[rear];
Step-3: Check If front = rear then
Set front = 0 and rear =0.
Else If front = size of queue Then
Front =1

Else
Front = front +1
End if.
Step-4: Print X.
Step-5: Finish.

Q.6. When we use doubly ended queue? Write separate algorithms for
deleting an element from a doubly ended queue and to insert an element
into a doubly ended queue.
Ans.

Algorithm Insert ( insert at rear )

Procedure Qinsert ( Q, F, R, N )
Q vector of queue
F front pointer of Queue.
R rear pointer of Queue.
N size of Queue.
X new value to be inserted.
Step-1: If ( R >= N) Then
Print Queue is Full
Else
R = R +1
Q[R]=X
If F = 0 Then
F=1
End if
End if

Step-2: Finish.

Algorithm Insert ( insert at front )

Procedure Qinsert (Q, F, R, N )


Q vector of queue
F front pointer of Queue.
R rear pointer of Queue.
N size of Queue.
X new value to be inserted.
Step-1: If ( F = 1 and R = N ) or F = R+1 Then
Print Queue is full.
Return.
End if.
Step-2: If F=1 Then
F=N.
Else if F=0 Then
F=R=1.
Else
F=F-1
End if.
Step-3: Q[F]=X.
Step-4: Finish.

Algorithm Delete ( delete from front )

Function DelQueue(Q, F, R, N )
Q vector of queue
F front pointer of Queue.

R rear pointer of Queue.


N size of Queue.
X value to be deleted.
Step-1: If F=0 then
Print Queue is empty.
Return.
End if.
Step-2: R = Q[F].
Step-3: F=F+1
Step-4: If F=R+1 Then
F=R=0
End if.
Step-5: return X.

Algorithm Delete ( delete from rear )

Function DelQueue(Q, F, R, N )
Q vector of queue
F front pointer of Queue.
R rear pointer of Queue.
N size of Queue.
X value to be deleted.
Step-1: If F=0 Then
Print Queue is empty.
Return;
End if.
Step-2: X=Q[R].
Step-3: If F=R Then

F=R=0.
Else if R=1 Then
R=N.
Else
R=R-1.
End if.
Step-4: return X.

You might also like