Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 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. //добавление
  10. void add(list **temp, int item)
  11. {
  12. list *t, *ptr;
  13. if (*temp == NULL)
  14. {
  15. *temp = (list *)malloc(sizeof(list));
  16. (*temp)->a = item;
  17. (*temp)->next = NULL;
  18. }
  19. else
  20. {
  21. t = (list *)malloc(sizeof(list));
  22. t->a = item;
  23. t->next = NULL;
  24. ptr = *temp;
  25. while (ptr->next != NULL)
  26. {
  27. ptr = ptr->next;
  28. }
  29. ptr->next = t;
  30. }
  31. }
  32. //вывод
  33. void print(list *temp)
  34. {
  35. while (temp != NULL)
  36. {
  37. printf("%d ", temp->a);
  38. temp = temp->next;
  39. }
  40. }
  41. int main()
  42. {
  43. list *temp = NULL;
  44. int a;
  45. while (1)
  46. {
  47. scanf_s("%d", &a);
  48. if (a == -1)
  49. break;
  50. add(&temp, a);
  51. }
  52. print(temp);
  53. _getch();
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement