Skip to content

Instantly share code, notes, and snippets.

@kachayev
Last active December 26, 2015 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kachayev/7166749 to your computer and use it in GitHub Desktop.
Save kachayev/7166749 to your computer and use it in GitHub Desktop.
data Skew a = Empty | Node a (Skew a) (Skew a)
singleton x = Node x Empty Empty
union t1 Empty = t1
union Emtpy t2 = t2
union t1@(Node x1 l1 r1) t2@(Node x2 l2 r2)
| x1 <= x2 = Node x1 (union t2 r1) l1
| otherwise = Node x2 (union t1 r2) l2
insert x heap = union (singleton x) heap
extractMin Empty = Nothing
extractMin (Node x l r) = Just (x, union l r)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment