Write an algorithm of inserting elements in a queue.
Answers
Answered by
8
Answer:
Data Structure and Algorithms - Queue. Advertisements. Queue is an abstract data structure, somewhat similar to Stacks. Unlike stacks, a queue is open at both its ends. One end is always used to insert data (enqueue) and the other is used to remove data (dequeue).
Answered by
9
Explanation:
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.
Similar questions