Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let swap tab a b =
- if a <> b then
- (
- let t = tab.(a) in
- tab.(a) <- tab.(b);
- tab.(b) <- t
- )
- in
- let msort tab a b =
- let m = b / 2 in
- let li = ref a in
- let ri = ref (a + m) in
- let s = ref 0 in
- for i = 0 to (b - 1) do
- if tab.(!li) > tab.(!ri) then
- (
- swap tab (a + i) (!ri);
- ri := !ri + 1;
- ) else
- (
- swap tab (a + i) (!li);
- if (!li + 1 < !ri) then
- li := !li + 1
- else
- li := a + i + 1
- )
- done
- in
- let rsort tab a b =
- if b > 1 then
- (
- let m = b / 2;
- rsort tab a m;
- rsort tab (a + m) (b - m);
- msort tab a b
- )
- in
- let sort tab =
- rsort tab 0 (length tab)
- in
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement