Page 177 - DCAP201_FUNDAMENTALS_OF_DATA_STRUCTURES
P. 177
Fundamentals of Data Structures
Notes The array element of priority queue can have the following structure:
struct data
{
int item;
int priority;
int order;
}
The structure holds the type of data item, priority of the element and the order in which the
element has been added.
Algorithm on inserting element in priority queue.
PQInsert (M, Item)
Step 1 Find the Row M
Step 2 [Reset the Rear Pointer]
If Rear[M] = N-1 then
Rear[M] = 0
Else
Rear[M] = Rear[M]+1
Step 3 [Overflow]
If Front[M] = Rear[M] then
Write (“This Priority Queue is full”)
Return
Step 4 [Insert Element]
Q[M] [Rear[M]] = then
Step 5 [Is Front Pointer Properly Set]
If Front[M] = -1 then
Front[m] = 0
Return
Step 6 Exit
Algorithm deleting element from Priority Queue
PQDelete (K, Item)
Step 1 Initialize K = 0
Step 2 while (Front[K] = -1)
K = K+1
[To find the first non empty queue]
Step 3 [Delete Element]
Item = Q[K] [Front[K]
Step 4 [Queue Empty]
If Front[K] = N-1 then
Front[K] = 0
Else
Front[K] = Front[K]+1
170 LOVELY PROFESSIONAL UNIVERSITY