File tree Expand file tree Collapse file tree 2 files changed +55
-1
lines changed
Expand file tree Collapse file tree 2 files changed +55
-1
lines changed Original file line number Diff line number Diff line change 1+ def main
2+
3+ def bsort: n as int, x as int []
4+
5+ def swap: x y as ref int
6+ var t is int
7+ t := x
8+ x := y
9+ y := t
10+
11+ var changed is byte
12+ var i is int
13+
14+ loop:
15+ changed := false
16+ i := 0
17+ loop:
18+ if i < n-1:
19+ if x[i] > x[i+1]:
20+ swap: x[i], x[i+1]
21+ changed := true
22+ i := i+1
23+ else: break
24+ if not changed: break
25+
26+ def writeArray: msg as byte [], n as int, x as int []
27+ var i is int
28+
29+ writeString: msg
30+ i := 0
31+ loop:
32+ if i < n:
33+ if i > 0: writeString: ", "
34+ writeInteger: x[i]
35+ i := i+1
36+ else: break
37+ writeString: "\n"
38+
39+ var seed i is int
40+ var x is int [16]
41+
42+ seed := 65
43+ i := 0
44+ loop:
45+ if i < 16:
46+ seed := (seed * 137 + 220 + i) % 101
47+ x[i] := seed
48+ i := i+1
49+ else: break
50+ writeArray: "Initial array: ", 16, x
51+ # according to the grammar, x here should be a proc-call of function `x` with no arguments
52+ # error should be that x is a variable of type int[16], not a function.
53+ bsort: 16 x
54+ writeArray: "Sorted array: ", 16, x
Original file line number Diff line number Diff line change @@ -48,5 +48,5 @@ def main
4848 i := i+1
4949 else: break
5050 writeArray: "Initial array: ", 16, x
51- bsort: 16 x
51+ bsort: 16, x
5252 writeArray: "Sorted array: ", 16, x
You can’t perform that action at this time.
0 commit comments