radixSort(List aList) { create an array of queues - Queue[] qs = new Queue[10]; initialize each Queue (! better than 10 null ptrs!) for each digit, d (from smallest to largest significance, i.e. 1, then 10, etc) { listToQueues() clear aList queuesToList() } // for each digit } // radixSort listToQueues() { for each element, e of aList{ qs[value at d].enqueue(e); } } queuesToList() { for each queue from 0-9 { while (!queue[i].isEmpty()) { aList.add(queue[i].dequeue()); } // while } // for each q }
void insert(Integer insertMe) {
if (isEmpty()) // base case
setRoot(insertMe);
else if (belongsOnTheRight(insertMe))
right.insert(insertMe);
else left.insert(insertMe);
}
insert new element at the insertion point (first empty slot, to the right of the step on the near-delta) swap up to it's proper place (to preserve heapness) i.e. if ! at root of heap if it is < its parent (i.e. is out of place) { swap roots with parent recurse on parent }running time?
save the root (to return) swap from rightmost, bottom row (to the left of the step on the near-delta) and trim the old root swap the root down to the proper place i.e. if ! a leaf if it is > either child (or just the left, if there's no right) { swap roots with smaller child recurse on that child }running time?
for each element in the list insert in the heap list.clear(); while !heap.isEmpty() list.add(heap.deleteRoot());