fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct list
  5. {
  6. int a;
  7. struct list *next;
  8. };
  9. typedef struct list List;
  10.  
  11. int main (void)
  12. {
  13. List *start = NULL, **end = &start;
  14. int a;
  15. while(scanf("%d", &a) == 1) {
  16. List *node = (List*)malloc(sizeof(List));
  17. node->a = a;
  18. node->next = NULL;
  19. *end = node;
  20. end = &node->next;
  21. }
  22. List *current = start;
  23. while(current) {
  24. printf("%d --> ", current -> a);
  25. current = current -> next;
  26. }
  27. current = start;
  28. while(current) {
  29. List *toDelete = current;
  30. current = current -> next;
  31. free(toDelete);
  32. }
  33. return 0;
  34. }
  35.  
  36.  
Success #stdin #stdout 0s 2292KB
stdin
1 2 3 4 5 6 7 8
stdout
1 --> 2 --> 3 --> 4 --> 5 --> 6 --> 7 --> 8 -->