fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct list {
  5. int key;
  6. struct list *prev, *next;
  7. };
  8.  
  9. struct list *append(struct list **l, int k)
  10. {
  11. *l = malloc(sizeof *l);
  12. (*l)->key = k;
  13. (*l)->next = NULL;
  14. return *l;
  15. }
  16.  
  17. void print(struct list *node)
  18. {
  19. while(node)
  20. {
  21. printf("%d\n", node->key);
  22. node = node->next;
  23. }
  24. }
  25.  
  26. int main(void)
  27. {
  28. struct list *l, *head;
  29. int i;
  30.  
  31. head = append(&l, -1);
  32. for (i = 0; i < 42; ++i)
  33. l = append(&l, i);
  34.  
  35. print(head);
  36. }
  37.  
Success #stdin #stdout 0.01s 1852KB
stdin
Standard input is empty
stdout
-1