Function Dequeue (Q)
The above Function deletes an element from the queue ‘Q’. Queue empty condition is checked by making a call to ‘IsEmpty’.
Step 1 Is Empty, call to IsEmpty
if (IsEmpty (Q)) then
message ‘Queue Empty’
return
else goto step 2.
Step 2 Deletion of an element
set temp ¬ Q (item [Q (front)])
Step 3 setting front and rear, if queue is empty
if Q (front) = Q(rear)) then
set Q (front) ¬ – 1
set Q (rear) ¬ – 1
else
set Q(front) ® Q(front) + 1
Step 4 return value at the time of call
return (temp)
Equivalent code is given below:
int Dequeue (queue* Q)
{
int temp
temp = Q ® item [Q ® front];
if (Q ® front = = Q ® rear)
Q ® front = Q ® rear = – 1;
else
Q ® front = Q ® front + 1;
return temp;
}
No comments:
Post a Comment