Last active
December 26, 2015 14:39
-
-
Save kachayev/7166749 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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