Commit | Line | Data |
---|---|---|
7f918cf1 CE |
1 | #include <stdio.h> |
2 | ||
3 | typedef unsigned int uint; | |
4 | ||
5 | typedef struct Cons { | |
6 | struct Cons *next; | |
7 | int value; | |
8 | } *Cons; | |
9 | ||
10 | Cons listCons (int n, Cons c) { | |
11 | Cons res; | |
12 | ||
13 | res = (Cons) malloc (sizeof(*res)); | |
14 | fprintf (stderr, "0x%08x = listCons (%d)\n", (uint)res, n); | |
15 | res->next = c; | |
16 | res->value = n; | |
17 | return res; | |
18 | } | |
19 | ||
20 | Cons listSing (int n) { | |
21 | Cons res; | |
22 | ||
23 | res = (Cons) malloc (sizeof(*res)); | |
24 | fprintf (stderr, "0x%08x = listSing (%d)\n", (uint)res, n); | |
25 | res->next = NULL; | |
26 | res->value = n; | |
27 | return res; | |
28 | } | |
29 | ||
30 | void listFree (Cons p) { | |
31 | fprintf (stderr, "listFree (0x%08x)\n", (uint)p); | |
32 | free (p); | |
33 | } | |
34 | ||
35 | int listSum (Cons c) { | |
36 | int res; | |
37 | ||
38 | fprintf (stderr, "listSum\n"); | |
39 | res = 0; | |
40 | for (; c != NULL; c = c->next) | |
41 | res += c->value; | |
42 | return res; | |
43 | } |