-
Notifications
You must be signed in to change notification settings - Fork 2
/
quicksort.i
165 lines (127 loc) · 3.79 KB
/
quicksort.i
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
NOTE .5 - array length ,5 - array of numbers
DO WRITE IN .5
DO ,5 <- .5
PLEASE NOTE Read numbers into ,5
DO NOTE .6 - current array index
DO .6 <- #1
DO NOTE <Begin loop>
PLEASE DO ABSTAIN .5 FROM (4)
(1) DO FORGET #1
DO WRITE IN ,5 SUB .6
DO .1 <- .6
PLEASE DO (1020) NEXT
DO .6 <- .1
(3) DO REINSTATE (4)
PLEASE DO (1) NEXT
(4) DO COME FROM (3)
DO NOTE <End loop>
DO .6 <- #1
DO .7 <- .5
DO (5) NEXT
(6) PLEASE NOTE Recursive function that splits ,5 in two parts
DO NOTE and sorts each recursively
DO NOTE Parameters: .6 - left index .7 - right index
(5) DO NOTE <Begin function>
DO STASH .6 + .7
PLEASE DO NOTE Check if .7 - .6 - 1 is negative. If yes then stop recursion
DO .1 <- .7
DO .2 <- .6
DO (1010) NEXT
PLEASE DO .1 <- .3
DO .2 <- #1
DO (1010) NEXT
DO .1 <- #1
PLEASE DO .2 <- .3~#32768
DO NOTE If .7 - .6 - 1 is negative .2 is #1 else #0
DO (1010) NEXT
DO NOTE If .7 - .6 - 1 is negative .3 is #0 else #1
DO ABSTAIN .3 FROM (8)
(7) DO NOTE .6 >= .7 so finish recursion
DO REINSTATE (8)
PLEASE NOTE Recursively sort two smaller parts
DO (9) NEXT
DO .9 <- .7
DO .1 <- .8
DO .2 <- #1
PLEASE DO (1010) NEXT
DO .7 <- .3
DO (5) NEXT
DO .1 <- .8
DO (1020) NEXT
DO .6 <- .1
DO .7 <- .9
PLEASE DO (5) NEXT
(8) DO COME FROM (7)
DO RETRIEVE .6 + .7
DO RESUME #1
DO NOTE <End function>
PLEASE NOTE Function that finds pivot and sorts by it
DO NOTE Parameters: .6 - left index .7 - right index
DO NOTE .8 - pivot position .9 - pivot value
DO NOTE 10 - number of iterations .11 - current index
(9) DO NOTE <Begin function>
DO .8 <- .6
PLEASE DO .9 <- ,5 SUB .7
DO .1 <- .7
DO .2 <- .6
DO (1010) NEXT
DO .10 <- .3
PLEASE DO .11 <- .6
DO NOTE <Begin loop>
DO ABSTAIN .10 FROM (13)
DO ABSTAIN FROM (10)
(10) DO FORGET #1
DO REINSTATE (10)
PLEASE NOTE Check if ,5 SUB .11 < .9
DO .1 <- ,5 SUB .11
DO .2 <- .9
DO (1010) NEXT
DO .1 <- #1
PLEASE DO .2 <- .3~#32768
DO NOTE If ,5 SUB .11 - .9 is negative .2 is #1 else #0
DO (1010) NEXT
DO NOTE If ,5 SUB .11 - .9 is negative .3 is #0 else #1
DO ABSTAIN .3 FROM (14)
DO ABSTAIN .3 FROM (15)
DO ABSTAIN .3 FROM (16)
PLEASE DO ABSTAIN .3 FROM (17)
DO ABSTAIN .3 FROM (18)
DO ABSTAIN .3 FROM (19)
(14) DO .12 <- ,5 SUB .8
(15) DO ,5 SUB .8 <- ,5 SUB .11
(16) PLEASE DO ,5 SUB .11 <- .12
(17) DO .1 <- .8
(18) DO (1020) NEXT
(19) DO .8 <- .1
DO REINSTATE (14)
PLEASE DO REINSTATE (15)
DO REINSTATE (16)
DO REINSTATE (17)
DO REINSTATE (18)
DO REINSTATE (19)
DO .1 <- .11
PLEASE DO (1020) NEXT
DO .11 <- .1
(12) DO REINSTATE (13)
PLEASE DO (10) NEXT
(13) DO COME FROM (12)
DO NOTE <End loop>
DO ,5 SUB .7 <- ,5 SUB .8
DO ,5 SUB .8 <- .9
DO RESUME #1
DO NOTE <End function>
DO COME FROM (6)
PLEASE NOTE Print array
DO .6 <- #1
DO NOTE <Begin loop>
PLEASE DO ABSTAIN .5 FROM (23)
(20) DO FORGET #1
DO READ OUT ,5 SUB .6
DO .1 <- .6
PLEASE DO (1020) NEXT
DO .6 <- .1
(22) DO REINSTATE (23)
PLEASE DO (20) NEXT
(23) DO COME FROM (22)
DO NOTE <End loop>
PLEASE GIVE UP