daily pastebin goal
40%
SHARE
TWEET

Untitled

a guest Aug 15th, 2018 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -module(mysort).
  2. -export([myMergeSort/1]).
  3.  
  4. myMergeSort([]) -> [];
  5. myMergeSort(MyList) -> mergeInPairs([ [X] || X <- MyList]).
  6. mergeInPairs([H|[]]) -> H;mergeInPairs([List1, List2 | T]) -> myMerge(mergeInPairs(T), myMerge(List1, List2)).
  7.  
  8. myMerge(MyList, []) -> MyList;
  9. myMerge([], MyList) -> MyList;
  10. myMerge(MyList1, MyList2) -> [H1|T1] = MyList1,
  11.                              [H2|T2] = MyList2,
  12.                              if
  13.                                 H1 < H2 ->
  14.                                         [H1|myMerge(T1, MyList2)];
  15.                                 true ->
  16.                                         [H2|myMerge(MyList1, T2)]
  17.                              end.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top