Homework B (benchmarks)
This commit is contained in:
parent
72cc3206c4
commit
76fbabdf53
141 changed files with 7540 additions and 2032 deletions
60
javali_tests/HWB/Quicksort.javali
Normal file
60
javali_tests/HWB/Quicksort.javali
Normal file
|
@ -0,0 +1,60 @@
|
|||
// Overall test of arrays, loops, etc. that does a simple quicksort.
|
||||
class Record {
|
||||
int a ;
|
||||
}
|
||||
|
||||
class Main {
|
||||
Record [] a;
|
||||
int i;
|
||||
|
||||
void swap(Record r1, Record r2) {
|
||||
int temp;
|
||||
temp = 0+1;
|
||||
temp = r1.a;
|
||||
r1.a = r2.a;
|
||||
r2.a = temp;
|
||||
}
|
||||
|
||||
void sort(int left, int right) {
|
||||
int i,j;
|
||||
int m;
|
||||
|
||||
m = (a[left].a + a[right].a) / (1 + 1);
|
||||
i = left;
|
||||
j = right;
|
||||
while (i <= j) {
|
||||
while (a[i].a < m) { i = i+1; }
|
||||
while (a[j].a > m) { j = j-1; }
|
||||
if (i <= j) {
|
||||
swap(a[i], a[j]);
|
||||
i = i+1;
|
||||
j = j-1;
|
||||
}
|
||||
}
|
||||
if (left < j) { sort(left,j); }
|
||||
if (i < right) { sort(i,right); }
|
||||
}
|
||||
|
||||
void main() {
|
||||
int SIZE;
|
||||
int j;
|
||||
|
||||
SIZE = 10;
|
||||
|
||||
a = new Record[SIZE * 1];
|
||||
j = 0;
|
||||
while (j < SIZE) {
|
||||
a[j] = new Record();
|
||||
a[j].a = read();
|
||||
j = j + 1;
|
||||
}
|
||||
sort(0, SIZE-1);
|
||||
j = 0;
|
||||
while (j < SIZE) {
|
||||
i = a[j].a;
|
||||
write(i);
|
||||
writeln();
|
||||
j = j + 1;
|
||||
}
|
||||
}
|
||||
}
|
10
javali_tests/HWB/Quicksort.javali.in
Normal file
10
javali_tests/HWB/Quicksort.javali.in
Normal file
|
@ -0,0 +1,10 @@
|
|||
1
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
5
|
||||
2
|
||||
4
|
||||
6
|
||||
3
|
Loading…
Add table
Add a link
Reference in a new issue