fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct node * link;
  5. struct node {
  6. int item;
  7. link next;
  8. };
  9.  
  10. int main(void) {
  11. link h, x, y;
  12. int i;
  13.  
  14. h = (link)malloc(sizeof(*x));
  15. h->next = NULL;
  16.  
  17. x = h;
  18. for (i = 0; i < 10; i++) {
  19. y = (link)malloc(sizeof(*y));
  20. y->item = rand()%100;
  21. y->next = NULL;
  22. x->next = y;
  23. x = y;
  24. }
  25.  
  26. for(x = h->next; x != NULL; x = x->next)
  27. printf("%d ", x->item);
  28.  
  29. printf("\n");
  30.  
  31. return 0;
  32. }
  33.  
Success #stdin #stdout 0s 4472KB
stdin
Standard input is empty
stdout
83 86 77 15 93 35 86 92 49 21