When we add a new element into this heap WHY we increase with totalNr while when we go throug heap elements up in this heap we do not,
I hope my question is clear !
1 2 3 4 5 6 7 8 9 10 11
void insert(const T value) { // value in heap
if (totalNr < long - 1) { // the place:
data[++totalNr] = value; // put it in the bottom. (data here pointer)
upHeap(totalNr); // upHeape
} else // no place in heap:
cout << "\nHeap is not empty " << long
<< " elements (includea. sen key)!\n\n";
}
> When we add a new element into this heap WHY we increase with totalNr
When a new element is added to the end of the array, the number of elements in the array goes up by one.
> while when we go throug heap elements up in this heap we do not,
When we go through the heap elements (upHeap), the elements in the array may be swapped around and their relative positions may change; but the total number of elements in the array remains what it was earlier.