Java Reference
In-Depth Information
64 index = childIndex;
65 }
66 else
67 {
68 // Root value is larger than both children
69 more = false ;
70 }
71 }
72 else
73 {
74 // No children
75 more = false ;
76 }
77 }
78
79 // Store root value in vacant slot
80 a[index] = rootValue;
81 }
82
83 /**
84 Swaps two entries of the array.
85 @param i the first position to swap
86 @param j the second position to swap
87 */
88 private void swap( int i, int j)
89 {
90 int temp = a[i];
91 a[i] = a[j];
92 a[j] = temp;
93 }
94
95 /**
96 Returns the index of the left child.
97 @param index the index of a node in this heap
98 @return the index of the left child of the given node
99 */
100 private static int getLeftChildIndex( int
index)
101 {
102 return 2 * index + 1 ;
103 }
Search WWH ::




Custom Search