// combine in each iteration those entries with the lowest weights
while(heap.size()>1){
HeapEntry a = heap.pop();
HeapEntry b = heap.pop();
heap.add(new HeapEntry(a.weight + b.weight, new InnerNode(a.node, b.node)));
}
// finally get the root (= last element in the heap!)
HeapEntry root = heap.pop();
return root.node;