Advertisement
venik2405

ocheredi

Nov 4th, 2021
1,093
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.20 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. typedef struct Node
  4. {
  5.     int value;
  6.     struct Node* next;
  7. } Spisok;
  8.  
  9. int getSize() {
  10.     int ind;
  11.     int size;
  12.     int flag;
  13.     do {
  14.         do {
  15.             rewind(stdin);
  16.             printf("Enter the size of the list\n");
  17.             ind = scanf_s("%d", &size);
  18.             if (ind != 1) {
  19.                 printf("Incorrect input!!!\n");
  20.             }
  21.         } while (ind != 1);
  22.         if ((size > 20) || (size < 1))
  23.         {
  24.             printf("Enter the size between 1 and 20");
  25.             flag = 1;
  26.         }
  27.         else {
  28.             flag = 0;
  29.         }
  30.     } while (flag == 1);
  31.     return size;
  32. }
  33.  
  34. int getNumber(int i) {
  35.     int ind;
  36.     int num;
  37.     int flag;
  38.     do {
  39.         do {
  40.             rewind(stdin);
  41.             printf("Enter element number %d: ", i + 1, "\n");
  42.             ind = scanf_s("%d", &num);
  43.             if (ind != 1) {
  44.                 printf("Incorrect input!!!\n");
  45.             }
  46.         } while (ind != 1);
  47.         if ((num > 50) || (num < -50))
  48.         {
  49.             printf("Enter the number, which is higher than -50 and lower than 50\n");
  50.             flag = 1;
  51.         }
  52.         else {
  53.             flag = 0;
  54.         }
  55.     } while (flag == 1);
  56.     return num;
  57. }
  58.  
  59. Spisok* create(int data)
  60. {
  61.     Spisok* tmp = (Spisok*)malloc(sizeof(Spisok));
  62.     tmp->value = data;
  63.     tmp->next = NULL;
  64.     return(tmp);
  65. }
  66.  
  67. void add_element_end(int data, Spisok* head)
  68. {
  69.     Spisok* tmp = (Spisok*)malloc(sizeof(Spisok));
  70.     tmp->value = data;
  71.     tmp->next = NULL;
  72.     Spisok* p = head;
  73.     while (p->next != NULL)
  74.         p = p->next;
  75.     p->next = tmp;
  76. }
  77.  
  78. Spisok* remove_all(Spisok* head)
  79. {
  80.     while (head != NULL)
  81.     {
  82.         Spisok* p = head;
  83.         head = head->next;
  84.         free(p);
  85.     }
  86.     return NULL;
  87. }
  88.  
  89.  
  90. void outputList(Spisok* tmp) {
  91.     while (tmp != NULL)
  92.     {
  93.         printf("%d ", tmp->value);
  94.         tmp = tmp->next;
  95.     }
  96. }
  97.  
  98. int main() {
  99.     int size = 0;
  100.     int num = 0;
  101.     size = getSize();
  102.     num = getNumber(0);
  103.     Spisok* myList = create(num);
  104.     for (int i = 1; i < size; i++) {
  105.         num = getNumber(i);
  106.         add_element_end(num, myList);
  107.     }
  108.     outputList(myList);
  109.     remove_all(myList);
  110.     printf("\n\n\n\n%d", 13 - 23 % 13);
  111.     return 1;
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement