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