Data update
This commit is contained in:
parent
81fd053722
commit
52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions
|
|
@ -0,0 +1,23 @@
|
|||
100 SIZE = 8
|
||||
110 SIZE = SIZE - 1 : DIM A(SIZE + RND (0) * 0): FOR I = 0 TO SIZE:A(I) = INT ( RND (1) * 98 + 1): NEXT I
|
||||
120 PRINT "UNSORT:";: GOSUB 160" PRINT ARRAY
|
||||
130 GOSUB 200" GNOMESORT
|
||||
140 PRINT CHR$ (13)" SORT:";: GOSUB 160" PRINT ARRAY
|
||||
150 END
|
||||
|
||||
REM PRINT ARRAY
|
||||
160 FOR I = 0 TO SIZE
|
||||
170 PRINT " "A(I);
|
||||
180 NEXT I
|
||||
190 RETURN
|
||||
|
||||
REM GNOMESORT
|
||||
200 LET I = 1
|
||||
210 FOR J = 2 TO SIZE + 1
|
||||
220 IF A(I - 1) < = A(I) THEN I = J: NEXT J: RETURN
|
||||
230 LET SWAP = A(I - 1):A(I - 1) = A(I):A(I) = SWAP
|
||||
240 LET I = I - 1
|
||||
250 IF I = 0 THEN I = J : NEXT J : RETURN
|
||||
260 LET J = J - 1
|
||||
270 NEXT J
|
||||
280 RETURN
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
void gnomeSort(List<int> arr) {
|
||||
int ub = arr.length - 1;
|
||||
int i = 0 + 1;
|
||||
int j = 0 + 2;
|
||||
|
||||
while (i <= ub) {
|
||||
if (arr[i - 1] <= arr[i]) {
|
||||
i = j;
|
||||
j++;
|
||||
} else {
|
||||
int temp = arr[i - 1];
|
||||
arr[i - 1] = arr[i];
|
||||
arr[i] = temp;
|
||||
i--;
|
||||
if (i == 0) {
|
||||
i = j;
|
||||
j++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
List<int> array = [-7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7];
|
||||
array.shuffle(); // Unsort the array
|
||||
|
||||
print("unsort: $array");
|
||||
gnomeSort(array); // Sort the array
|
||||
print(" sort: $array");
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue