summaryrefslogtreecommitdiff
path: root/tigrou/sort/sort.tih
blob: c601fe36f578f37c69b4666934051d7657834b91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
	)