Advertisement
Zennoma

pust_budet_laba

Dec 14th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.85 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. struct spisok
  5. {
  6.     int num;
  7.     spisok* next;
  8. };
  9.  
  10.  
  11. void pechat(spisok* first)
  12. {
  13.     spisok* t = first;
  14.  
  15.     while (t != NULL)
  16.     {
  17.         printf_s("%d", t->num);
  18.         puts("");
  19.         t = t->next;
  20.     }
  21. }
  22. void main()
  23. {
  24.     spisok* first, * q, * n, * perviy, * p, * t;
  25.     char stroka[15];
  26.    
  27.             first = NULL;
  28.             first = new spisok;
  29.             gets_s(stroka, 15);
  30.             first->num = atoi(stroka);
  31.             first->next = NULL;
  32.             n = first;
  33.  
  34.             while (gets_s(stroka,15),strlen(stroka)!=0,atoi(stroka)!=0)
  35.             {
  36.                 q = new spisok;
  37.                 n->next = q;
  38.                 n = n->next;
  39.                 q->num = atoi (stroka);
  40.                 q->next = NULL;
  41.             }
  42.  
  43.  
  44.             perviy = NULL;
  45.             perviy = new spisok;
  46.             gets_s(stroka, 15);
  47.             perviy->num = atoi(stroka);
  48.             perviy->next = NULL;
  49.             t = perviy;
  50.             while (gets_s(stroka, 15), strlen(stroka) != 0)
  51.             {
  52.                 p = new spisok;
  53.                 t->next = p;
  54.                 t = t->next;
  55.                 p->num = atoi(stroka);
  56.                 p->next = NULL;
  57.             }
  58.             puts("pervya");
  59.             pechat(first);
  60.             puts("vtoroy");
  61.             pechat(perviy);
  62.             puts("sorted");
  63.             q = first;
  64.             p = perviy;
  65.             while (q != NULL || p != NULL)
  66.             {
  67.                 if (q->num < p->num)
  68.                 {
  69.                     printf_s("%d", q->num);
  70.                     puts("");
  71.                     q = q->next;
  72.                 }
  73.  
  74.                 else
  75.                 {
  76.                     printf_s("%d", p->num);
  77.                     puts("");
  78.                     p = p->next;
  79.                 }
  80.  
  81.                 if (q == NULL)
  82.                 {
  83.                     while (p != NULL)
  84.                     {
  85.                         printf_s("%d", p->num);
  86.                         puts("");
  87.                         p = p->next;
  88.                     }
  89.                 }
  90.                 if (p == NULL)
  91.                 {
  92.                     while (q!=NULL )
  93.                     {
  94.                         printf_s("%d", q->num);
  95.                         puts("");
  96.                         q = q->next;
  97.                     }
  98.                 }
  99.  
  100.             }
  101.  
  102.             while (first != NULL)
  103.             {
  104.                
  105.                 q = first->next;
  106.                 delete first;
  107.                 first = q;
  108.                
  109.             }
  110.             while (perviy != NULL)
  111.             {
  112.  
  113.                 q = perviy->next;
  114.                 delete perviy;
  115.                 perviy = q;
  116.  
  117.             }
  118.             pechat(first);
  119.             pechat(perviy);
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement