Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <conio.h>
  4. typedef struct LIST
  5. {
  6. int a;
  7. struct LIST *next;
  8. }list;
  9. list *add(list *temp, int item)
  10. {
  11. list *t;
  12. if (temp == NULL)
  13. {
  14. temp = (list *)malloc(sizeof(list));
  15. temp->a = item;
  16. temp->next = NULL;
  17. }
  18. else
  19. {
  20. while (temp->next != NULL)
  21. {
  22. temp = temp->next;
  23. }
  24.  
  25. t = (list *)malloc(sizeof(list));
  26. t->a = item;
  27. t->next = NULL;
  28. temp->next = t;
  29. }
  30. return temp;
  31. }
  32. void print(list *temp)
  33. {
  34. while (temp != NULL)
  35. {
  36. printf("%d ", temp->a);
  37. temp = temp->next;
  38. }
  39. }
  40. int main()
  41. {
  42. list *temp = NULL;
  43. int a;
  44. while (1)
  45. {
  46. scanf_s("%d", &a);
  47. if (a == -1)
  48. break;
  49. add(temp, a);
  50. }
  51. print(temp);
  52. _getch();
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement