-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSTALINSORT.rpgle
More file actions
45 lines (37 loc) · 900 Bytes
/
Copy pathSTALINSORT.rpgle
File metadata and controls
45 lines (37 loc) · 900 Bytes
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
**free
ctl-opt dftactgrp(*no);
// Stalin Sort
dcl-s arr int(10) dim(6);
dcl-s size uns(3) inz(6);
dcl-s i uns(3);
arr = %list(1 : 2 : 5 : 4 : 1 : 6);
stalin_sort(arr : size);
dsply ('New Size : ' + %char(size));
for i = 1 to size;
dsply arr(i);
endfor;
return;
dcl-proc stalin_sort;
dcl-pi *n;
array int(10) dim(6);
size uns(3);
end-pi;
dcl-s i like(size);
dcl-s write_index like(size) inz(1);
dcl-s newsize like(size) inz(0);
dcl-s lastval int(10) inz(*loval);
if size <= 1;
return;
endif;
for i = 1 to size;
if array(i) >= lastval;
lastval = array(i);
if write_index <> i;
array(write_index) = lastval;
endif;
newsize += 1;
write_index += 1;
endif;
endfor;
size = newsize;
end-proc;