Created
December 21, 2019 03:53
-
-
Save snoble/db30a967a1ce1a4f80a57549f52f4ddd to your computer and use it in GitHub Desktop.
Merging
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
package Merge | |
def split(sorted, at): | |
recur sorted: | |
[]: ([], []) | |
[h, *rest]: | |
match cmp_Int(h, at): | |
GT: ([], sorted) | |
_: | |
(left, right) = split(rest, at) | |
([h, *left], right) | |
def merge(sorted1, sorted2): | |
recur sorted1: | |
[]: sorted2 | |
[head1, *rest1]: | |
match sorted2: | |
[]: sorted1 | |
_: | |
(left, right) = split(sorted2, head1) | |
[*left, head1, *merge(rest1, right)] | |
out = merge([1,2,5,6,8],[4,6,7]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment