Logo 
Search:

C++ Programming FAQ

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

Write an algorithm for Inserting an element into the queue using array in dfs

  Shared By: Lujza Fischer    Date: Nov 08    Category: C++ Programming    Views: 12765

Answer:

PROCEDURE ADD(QUEUE, F, R, N, item)
[This will inserts ‘item’ in the ‘queue’ after ‘R (rare)’ where ‘n’ is size of array.]

1. [Overflow ?]

if (R >= N)
write Stack is full.
return.

2. [Increment R]

R <-- R + 1

3. [Insert Element]

QUEUE [R] <-- item.

4. [Setting the ‘F (Front)’ pointer]

if (F=0)
F=1
return.

Share: 
 


Related Topics:

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


Tagged: