File tree 1 file changed +0
-32
lines changed
Data Structures and Algorithms (English) 1 file changed +0
-32
lines changed Original file line number Diff line number Diff line change 1
-
2
- typedef int ElementType ;
3
- #define MinData -1
4
-
5
- typedef struct HeapStruct * PriorityQueue ;
6
- struct HeapStruct {
7
- ElementType * Elements ;
8
- int Capacity ;
9
- int Size ;
10
- };
11
-
12
- PriorityQueue Initialize ( int MaxElements ); /* details omitted */
13
-
14
- void PercolateUp ( int p , PriorityQueue H );
15
- void PercolateDown ( int p , PriorityQueue H );
16
-
17
- void Insert ( ElementType X , PriorityQueue H )
18
- {
19
- int p = ++ H -> Size ;
20
- H -> Elements [p ] = X ;
21
- PercolateUp ( p , H );
22
- }
23
-
24
- ElementType DeleteMin ( PriorityQueue H )
25
- {
26
- ElementType MinElement ;
27
- MinElement = H -> Elements [1 ];
28
- H -> Elements [1 ] = H -> Elements [H -> Size -- ];
29
- PercolateDown ( 1 , H );
30
- return MinElement ;
31
- }
32
-
33
1
void PercolateUp ( int p , PriorityQueue H ) {
34
2
while (p > 1 ) {
35
3
int parent = p / 2 ;
You can’t perform that action at this time.
0 commit comments