5
Challenge
You must, in the least bytes possible, implement the Binary Heap data structure and each of the following methods that operate on it:
- A function which takes no arguments and returns an empty Heap
- A function which takes a list of arguments with an arbitrary length and returns a Heap containing the elements
- A function which takes two Heaps and merges them into a new Heap, returning it
- A function which removes the root element of the Heap and reorders it accordingly, returning the root and new Heap
- A function which takes an integer and a Heap, inserts it into the Heap, and returns the Heap
Clarifications
- Your heap must be implemented as linking nodes created with structs, classes, custom types or equivalent, not using an array or list
- You may implement either a max-heap or a min-heap, it is your choice.
- You may assume that only integers are being stored in the heap
- Your functions must be bound to a variable or name (and callable, obviously)
- Standard loopholes are disallowed
No builtins, I'm guessing? – Sp3000 – 2015-01-15T01:34:29.460
@Sp3000 Any built in heap type or methods operating on that type are disallowed, yes. – globby – 2015-01-15T01:36:13.263