Procedure EnCqueue (Q, data)
This procedure inserts value data in circular queue.
Step 1 If Empty
if (CQ (front = – 1) then
{
set CQ (front) ¬ 0
set CQ (rear) ¬ 0
}
elseif (CQ (rear) = (SIZE – 1) then
set CQ (rear) = 0
else
set CQ(rear) ¬ CQ(rear) + 1
Step 2 Inserts value at rear end
set CQ (item [CQ (rear)]) ¬ data
Step 3 return at the point of call
return
Equivalent C code is given below:
void EnCqueue (queue * CQ, int data)
{
if (CQ ® front = = – 1
Q ® front = CQ ® rear = 0;
else if (CQ ® rear = = SIZE – 1
CQ ® rear = 0;
else
CQ ® rear = CQ ® rear + 1; ...(i)
CQ ® item [CQ ® rear] = data;
}
No comments:
Post a Comment