User Tools

Site Tools


info:teaching:pprog15

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
info:teaching:pprog15 [2015/02/19 07:35]
moritz eclipse tricks
info:teaching:pprog15 [2015/05/21 15:22] (current)
moritz link slides
Line 2: Line 2:
   * [[info:​java|Java tips]]   * [[info:​java|Java tips]]
   * [[info:​eclipse_cheat_sheet|Eclipse tricks]]   * [[info:​eclipse_cheat_sheet|Eclipse tricks]]
 +
 +===== Class 12 =====
 +
 +Slides: [[http://​people.inf.ethz.ch/​gerbesim/​teaching/​pprog15/​index.html]] Danke an Simon G.!
 +
 +===== Class 10 =====
 +<​code>​
 +#include <​stdio.h>​
 +#include <​stdlib.h>​
 +
 +struct node {
 +    int value;
 +    struct node *next;
 +};
 +
 +void insert(struct node *list, struct node *element) {
 +    element->​next = list->​next;​
 +    list->​next = element;
 +}
 +
 +void print(struct node *e) {
 +    printf("​e->​value=%d\n",​ e->​value);​
 +}
 +
 +void apply(void (*f)(struct node *), struct node *list) {
 +    while (list) {
 +        f(list);
 +        list = list->​next;​
 +    }
 +}
 +
 +
 +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->​value = i << 2;
 +        insert(&​list,​ element);
 +    }
 +    struct node *current = &list;
 +/*
 +    while (current) {
 +        printf("​%d ", current->​value);​
 +        current = current->​next;​
 +    }
 +    printf("​\n"​);​ */
 +
 +    apply(&​print,​ &list);
 +
 +    current = list.next;
 +    while (current) {
 +        printf("​%d ", current->​value);​
 +        struct node *n = current;
 +        current = current->​next;​
 +        free(n);
 +    }
 +
 +    printf("​Hello world!\n"​);​
 +    return 0;
 +}
 +</​code>​
 +
info/teaching/pprog15.1424327732.txt.gz · Last modified: 2015/02/19 07:35 by moritz