Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. #include "stdlib.h"
  2. #include <iostream>
  3. using namespace std;
  4. struct node
  5. {
  6. int info;
  7. node* next;
  8. };
  9. typedef node* NodeP; // указатель на тип node
  10. NodeP head = NULL; // указатель на начало списка
  11. NodeP p; // указатель на текущий элемент
  12. NodeP tail;
  13. int number;
  14. node* create(NodeP)
  15. {
  16. int let = 1;
  17. int i, num;
  18. tail = head; // указатель на конец списка
  19. while (let)
  20. {
  21. printf("vv elem\n");
  22. scanf_s("%d", &number);
  23. p = (node*)malloc(sizeof(node));
  24. if (head == NULL) // если список пуст
  25. {
  26. head = p;// выделение памяти для нового элемента
  27. head->info = number; // запись значения в список
  28. head->next = NULL;
  29. tail = head;
  30. }
  31. else
  32. {
  33. p->info = number;
  34. tail->next = p;
  35. p->next = NULL;
  36. tail = p;
  37. printf("continue (1/0)? ");
  38. scanf_s("%d", &let);
  39. }
  40. }
  41. return tail;
  42. }
  43. void SearchZn(NodeP)
  44. {
  45. tail = head;
  46. while (tail != NULL)
  47. {
  48. printf("%d\n", tail->info);
  49. tail = tail->next;
  50. }
  51. if (tail == NULL)
  52. cout << "net znachenia" << endl;
  53. return;
  54. }
  55. int main()
  56. {
  57. int menu;
  58. create(p);
  59. SearchZn(p);
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement