blob: 281b919f3c7c0319457b5b1ff60a192b5cc6ecc1 (
plain)
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
|
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
struct cons { int hd; struct cons * tl; };
typedef struct cons * list;
extern list buildlist(int n);
extern list reverselist(list l);
int checklist(int n, list l)
{
int i;
for (i = 0; i <= n; i++) {
if (l == NULL) return 0;
if (l->hd != i) return 0;
l = l->tl;
}
return (l == NULL);
}
int main(int argc, char ** argv)
{
int n;
if (argc >= 2) n = atoi(argv[1]); else n = 10;
if (checklist(n, reverselist(buildlist(n)))) {
printf("OK\n");
return 0;
} else {
printf("Bug!\n");
return 2;
}
}
|