Logo 
Search:

C++ Programming FAQ

Submit Interview FAQ
Home » Interview FAQ » C++ ProgrammingRSS Feeds

Write an algorithm for Inserting an element from the circular queue using array in dfs.

  Shared By: Bradley Evans    Date: Apr 24    Category: C++ Programming    Views: 7383

Answer:

PROCEDURE CQINSERT(QUEUE, F, R, item,N)
[Inserts ‘item’ into the ‘queue’, ‘F’ is the Front end pointer and ‘R’ is the rare end pointer and ‘N’ is the number of elements in queue]

1. [Reset rare pointer]

if (R = N)
then R <-- 1
else
R <-- R + 1.

2. [Overflow ?]

if (F = R)
write Stack is full.
return.

3. [Insert element]

QUEUE [R] <-- item

4. [Setting front pointer]

if (F = 0)
then F <-- 1
return.

Share: 
 


Related Topics:

Your Comment
  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].


Tagged: