fork download
  1. #include <stdio.h>
  2.  
  3. struct list{
  4. int data;
  5. struct list *next;
  6. };
  7.  
  8. struct list * insert(struct list *node, int data){
  9. struct list *tmp = (struct list*)malloc(sizeof(struct list));
  10.  
  11. if (tmp != NULL){
  12. tmp->data = data;
  13. if (node != NULL){
  14. tmp->next = node->next;
  15. node->next = tmp;
  16. }else{
  17. tmp->next = NULL;
  18. }
  19. }
  20.  
  21. return tmp;
  22. }
  23.  
  24.  
  25. int main(void) {
  26. struct list *root = NULL;
  27. struct list **tmp = &root;
  28. for(int i = 1; i < 10; i++){
  29. *tmp = insert(*tmp, i*16 % 9);
  30. tmp = &(*tmp)->next;
  31. }
  32. return 0;
  33. }
  34.  
Success #stdin #stdout 0s 2240KB
stdin
Standard input is empty
stdout
Standard output is empty