--- Ukesoppgave om huffmantr?r proc HuffmanLeaves(tree, chars): if v.symbol == null: HuffmanLeaves(v.left, chars) HuffmanLeaves(v.right, chars) else: add (v.symbol, v.freq) to chars return chars --- Ukesoppgave om heap class Heap: Heap(x): this.head = Node(x) this.size = 1 class Node: Node(x): this.elem = x this.left = null this.right = null this.parent = null method bubbleDown(): if this.left == null: return minChild = this.left if this.right != null and this.right.elem < minChild.elem: minChild = this.right if this.elem > minChild.elem: this.elem, minChild.elem = minChild.elem, this.elem minChild.bubbleDown() method bubbleUp(): if this.parent == null: return if this.parent.elem > this.elem: this.parent.elem, this.elem = this.elem, this.parent.elem this.parent.bubbleUp() method insert(x): node = Node(x) this.addLast(node) node.bubbleUp() method removeMin(): min = this.head.elem oldLast = this.removeLast() this.head.elem = oldLast.elem this.head.bubbleDown() method addLast(newNode): this.size += 1 path = binary representation of this.size node = this.head for digit in path[1..]: if digit == 0: if node.left != null: node = node.left else: node.left = newNode else: if node.right != null: node = node.right else: node.right = newNode method removeLast(): path = binary representation of this.size node = this.head for digit in path[1..]: if digit == 0: node = node.left else: node = node.right if path[path.length - 1] == 0: node.parent.left = null else: node.parent.right = null this.size -= 1 return node