mirror of
https://github.com/ProgramSnail/Lama.git
synced 2025-12-06 14:58:50 +00:00
31 lines
No EOL
490 B
Text
31 lines
No EOL
490 B
Text
fun compare (x, y) {
|
|
x - y
|
|
}
|
|
|
|
fun bubbleSort (l) {
|
|
fun inner (l) {
|
|
case l of
|
|
x : z@(y : tl) ->
|
|
if compare (x, y) > 0
|
|
then [true, y : inner (x : tl) [1]]
|
|
else case inner (z) of [f, z] -> [f, x : z] esac
|
|
fi
|
|
| _ -> [false, l]
|
|
esac
|
|
}
|
|
|
|
fun rec (l) {
|
|
case inner (l) of
|
|
[true , l] -> rec (l)
|
|
| [false, l] -> l
|
|
esac
|
|
}
|
|
|
|
rec (l)
|
|
}
|
|
|
|
fun generate (n) {
|
|
if n then n : generate (n-1) else {} fi
|
|
}
|
|
|
|
bubbleSort (generate (1000)) |