1: public void add(T newEntry)
2: {
3: checkInitialization(); // Ensure initialization of data fields
4: int newIndex = lastIndex + 1;
5: int parentIndex = newIndex / 2;
6: while ( (parentIndex > 0) && newEntry.compareTo(heap[parentIndex]) > 0)
7: {
8: heap[newIndex] = heap[parentIndex];
9: newIndex = parentIndex;
10: parentIndex = newIndex / 2;
11: } // end while
12:
13: heap[newIndex] = newEntry;
14: lastIndex++;
15: ensureCapacity();
16: } // end add
17: // Version 4.0