Java Reference
In-Depth Information
109 // root is smaller than both children
110 more = false ;
111 }
112 }
113 else
114 {
115 // No children
116 more = false ;
117 }
118 }
119
120 // Store root element in vacant slot
121 elements.set(index, root);
122 }
123
124 /**
125 Returns the number of elements in this heap.
126 */
127 public int size()
128 {
129 return elements.size() - 1 ;
130 }
131
132 /**
133 Returns the index of the left child.
134 @param index the index of a node in this heap
135 @return the index of the left child of
the given node
136 */
137 private static int getLeftChildIndex( int
index)
138 {
139 return 2 * index;
140 }
141
142 /**
143 Returns the index of the right child.
144 @param index the index of a node in this heap
145 @return the index of the right child of the given node
146 */
748
Search WWH ::




Custom Search