PRIORITY QUEUE
USING HEAP
Aim:
To
implement priority queue using Heap in C program.
Algorithm:
Step
1: [Include necessary header files]
Step
2: [Define maxsize as 15]
Step
3: [Declare necessary variables]
Step
4: READ option, opt
IF
opt is 1 THEN CALL INSERT()
IF
opt is 2 THEN CALL DELMAX()
IF
opt is 3 THEN CALL DIS()
Step
5: [END OF MAIN FUNCTION]
Algorithm For
INSERT()
Step 1: I ne1+1
Step 2: IF (I MAXSIZE)
WRITE
(“ Heap size exceeded”)
RETURN
FALSE
IF
( (I> 1) && (arraysize [i/2]< item) )
array[I] array[i/2]
I I/2
Array[I ] item
RETURN TRUE
Algorithm For
DELMAX()
Step
1: IF (!nel)
WRITE
(“HEAP IS EMPTY”)
ELSE
*item array [I]
Array[i] array [nel--]
CALL
adjust (array,I,nel)
No comments:
Post a Comment