summaryrefslogtreecommitdiff
path: root/tigrou/sort/sort.tih
diff options
context:
space:
mode:
Diffstat (limited to 'tigrou/sort/sort.tih')
-rw-r--r--tigrou/sort/sort.tih24
1 files changed, 24 insertions, 0 deletions
diff --git a/tigrou/sort/sort.tih b/tigrou/sort/sort.tih
new file mode 100644
index 0000000..c601fe3
--- /dev/null
+++ b/tigrou/sort/sort.tih
@@ -0,0 +1,24 @@
+type int_array = array of int
+function sort(a : int_array, size : int) =
+ if size > 0 then
+ (
+ let var swapped := 0
+ in
+ for i := 0 to size do
+ (
+ swapped := 0;
+ (for j := 1 to size - i - 1 do
+ if a[j - 1] > a[j] then
+ (
+ (let var tmp := a[j - 1]
+ in
+ a[j - 1] := a[j];
+ a[j] := tmp
+ end);
+ swapped := 1
+ ));
+ if swapped = 0 then
+ break
+ )
+ end
+ )