fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct list {
  5. struct list *m_pNext;
  6. int m_value;
  7. } List;
  8.  
  9. List *list_insert(List *pHead, int value)
  10. {
  11. struct list *pNew = malloc(sizeof(List));
  12. pNew->m_value = value;
  13. pNew->m_pNext = pHead;
  14.  
  15. return pNew;
  16. }
  17.  
  18. void list_print(List *pHead)
  19. {
  20. List *p;
  21.  
  22. for (p = pHead; p; p = p->m_pNext) {
  23. printf("%d ", p->m_value);
  24. }
  25. printf("\n");
  26. }
  27.  
  28. void list_free(List *pHead)
  29. {
  30. List *p, *q;
  31.  
  32. for (p = pHead; p; p = q) {
  33. q = p->m_pNext;
  34. free(p);
  35. }
  36. }
  37.  
  38. int main()
  39. {
  40. List *pHead = NULL;
  41. int value;
  42.  
  43. for (; ;) {
  44. if (scanf("%d", &value) < 1) {
  45. continue;
  46. }
  47. if (value < 0) {
  48. break;
  49. }
  50.  
  51. pHead = list_insert(pHead, value);
  52. }
  53.  
  54. list_print(pHead);
  55.  
  56. return 0;
  57. }
  58.  
Success #stdin #stdout 0.02s 1812KB
stdin
8 8 0 1 6 8 0 0 -1
stdout
0 0 8 6 1 0 8 8