Skew Heap

- the fun of programming

- data Skew a
- empty :: Skew a
- singleton :: a -> Skew a
- insert :: Ord a => a -> Skew a -> Skew a
- fromList :: Ord a => [a] -> Skew a
- toList :: Skew a -> [a]
- deleteMin :: Ord a => Skew a -> Skew a
- null :: Skew t -> Bool
- merge :: Ord a => Skew a -> Skew a -> Skew a
- minimum :: Skew a -> Maybe a
- valid :: Ord a => Skew a -> Bool
- heapSort :: Ord a => Skew a -> [a]

# Data structures

# Creating heaps

insert :: Ord a => a -> Skew a -> Skew aSource

Insertion.

`>>>`

True`insert 7 (fromList [5,3]) == fromList [3,5,7]`

`>>>`

True`insert 5 empty == singleton 5`

fromList :: Ord a => [a] -> Skew aSource

Creating a heap from a list.

`>>>`

True`empty == fromList []`

`>>>`

True`singleton 'a' == fromList ['a']`

`>>>`

True`fromList [5,3] == fromList [5,3]`

# Converting to a list

Creating a list from a heap. O(N)

`>>>`

`let xs = [5,3,5]`

`>>>`

True`length (toList (fromList xs)) == length xs`

`>>>`

[]`toList empty`

# Deleting

deleteMin :: Ord a => Skew a -> Skew aSource

Deleting the minimum element.

`>>>`

True`deleteMin (fromList [5,3,7]) == fromList [5,7]`

`>>>`

True`deleteMin empty == empty`

# Checking heaps

See if the heap is empty.

`>>>`

True`Data.Heap.Skew.null empty`

`>>>`

False`Data.Heap.Skew.null (singleton 1)`

# Helper functions

merge :: Ord a => Skew a -> Skew a -> Skew aSource

Merging two heaps

`>>>`

True`merge (fromList [5,3]) (fromList [5,7]) == fromList [3,5,5,7]`