test subdirectory
This commit is contained in:
parent
b4dbce76cf
commit
bf7f456967
31 changed files with 19 additions and 13 deletions
47
test/old/sort.c
Normal file
47
test/old/sort.c
Normal file
|
@ -0,0 +1,47 @@
|
|||
int printf(char* format, ...);
|
||||
int scanf(char* format, ...);
|
||||
int exit(int status);
|
||||
|
||||
void assert_eq(int expected, int actual) {
|
||||
if (expected != actual) {
|
||||
printf("expected: %d, actual: %d\n", expected, actual);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
void swap(int* a, int* b) {
|
||||
int t = *a;
|
||||
*a = *b;
|
||||
*b = t;
|
||||
}
|
||||
|
||||
void sort(int a[], int n) {
|
||||
for (int i = 0; i < n; i++) {
|
||||
for (int j = i + 1; j < n; j++) {
|
||||
if (a[i] > a[j]) {
|
||||
swap(&a[i], &a[j]);
|
||||
assert_eq(i - j, &a[i] - &a[j]);
|
||||
assert_eq(j - i, &a[j] - &a[i]);
|
||||
assert_eq(a[i], *(a + i));
|
||||
assert_eq(i[a], *(i + a));
|
||||
assert_eq(a[j - i], *(a + (j - i)));
|
||||
assert_eq(j[a - i], *(j + (a - i)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int a[100];
|
||||
int n;
|
||||
|
||||
int main() {
|
||||
scanf("%d", &n);
|
||||
for (int i = 0; i < n; i++) {
|
||||
scanf("%d", &a[i]);
|
||||
}
|
||||
sort(a, n);
|
||||
for (int i = 0; i < n; i++) {
|
||||
printf("%d ", a[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue