info:teaching:pprog15
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| info:teaching:pprog15 [2015/02/19 06:35] – eclipse tricks moritz | info:teaching:pprog15 [2015/05/21 13:22] (current) – link slides moritz | ||
|---|---|---|---|
| Line 2: | Line 2: | ||
| * [[info: | * [[info: | ||
| * [[info: | * [[info: | ||
| + | |||
| + | ===== Class 12 ===== | ||
| + | |||
| + | Slides: [[http:// | ||
| + | |||
| + | ===== Class 10 ===== | ||
| + | < | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | struct node { | ||
| + | int value; | ||
| + | struct node *next; | ||
| + | }; | ||
| + | |||
| + | void insert(struct node *list, struct node *element) { | ||
| + | element-> | ||
| + | list-> | ||
| + | } | ||
| + | |||
| + | void print(struct node *e) { | ||
| + | printf(" | ||
| + | } | ||
| + | |||
| + | void apply(void (*f)(struct node *), struct node *list) { | ||
| + | while (list) { | ||
| + | f(list); | ||
| + | list = list-> | ||
| + | } | ||
| + | } | ||
| + | |||
| + | |||
| + | int main() | ||
| + | { | ||
| + | int i; | ||
| + | struct node list; | ||
| + | list.value = 99999; | ||
| + | list.next = NULL; | ||
| + | |||
| + | for (i = 1; i <= 10; i++) { | ||
| + | struct node *element = malloc(sizeof(struct node)); | ||
| + | if (element == NULL) { | ||
| + | return 1; | ||
| + | } | ||
| + | element-> | ||
| + | insert(& | ||
| + | } | ||
| + | struct node *current = &list; | ||
| + | /* | ||
| + | while (current) { | ||
| + | printf(" | ||
| + | current = current-> | ||
| + | } | ||
| + | printf(" | ||
| + | |||
| + | apply(& | ||
| + | |||
| + | current = list.next; | ||
| + | while (current) { | ||
| + | printf(" | ||
| + | struct node *n = current; | ||
| + | current = current-> | ||
| + | free(n); | ||
| + | } | ||
| + | |||
| + | printf(" | ||
| + | return 0; | ||
| + | } | ||
| + | </ | ||
| + | |||
info/teaching/pprog15.1424327732.txt.gz · Last modified: by moritz
