fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct ValueNode
  5. {
  6. int value;
  7. struct ValueNode *next;
  8. } ValueNode;
  9.  
  10. void insert(ValueNode **head,int value)
  11. {
  12. ValueNode *tmp=(ValueNode*)malloc(sizeof(ValueNode));
  13. tmp->value=value;
  14. tmp->next=*head;
  15. *head=tmp;
  16. }
  17.  
  18. void showValueNodes(ValueNode *head)
  19. {
  20. printf("{");
  21. for(;head;head=head->next) printf(" %d",head->value);
  22. printf(" }\n");
  23. }
  24.  
  25. int main()
  26. {
  27. ValueNode *head=NULL;
  28. showValueNodes(head);
  29. insert(&head,10);
  30. showValueNodes(head);
  31. insert(&head,20);
  32. showValueNodes(head);
  33. insert(&head,30);
  34. showValueNodes(head);
  35. return 0;
  36. }
Success #stdin #stdout 0s 2292KB
stdin
Standard input is empty
stdout
{ }
{ 10 }
{ 20 10 }
{ 30 20 10 }