Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- struct spisok
- {
- int num;
- spisok* next;
- };
- void pechat(spisok* first)
- {
- spisok* t = first;
- while (t != NULL)
- {
- printf_s("%d", t->num);
- puts("");
- t = t->next;
- }
- }
- void main()
- {
- spisok* first, * q, * n, * perviy, * p, * t;
- char stroka[15];
- first = NULL;
- first = new spisok;
- gets_s(stroka, 15);
- first->num = atoi(stroka);
- first->next = NULL;
- n = first;
- while (gets_s(stroka,15),strlen(stroka)!=0,atoi(stroka)!=0)
- {
- q = new spisok;
- n->next = q;
- n = n->next;
- q->num = atoi (stroka);
- q->next = NULL;
- }
- perviy = NULL;
- perviy = new spisok;
- gets_s(stroka, 15);
- perviy->num = atoi(stroka);
- perviy->next = NULL;
- t = perviy;
- while (gets_s(stroka, 15), strlen(stroka) != 0)
- {
- p = new spisok;
- t->next = p;
- t = t->next;
- p->num = atoi(stroka);
- p->next = NULL;
- }
- puts("pervya");
- pechat(first);
- puts("vtoroy");
- pechat(perviy);
- puts("sorted");
- q = first;
- p = perviy;
- while (q != NULL || p != NULL)
- {
- if (q->num < p->num)
- {
- printf_s("%d", q->num);
- puts("");
- q = q->next;
- }
- else
- {
- printf_s("%d", p->num);
- puts("");
- p = p->next;
- }
- if (q == NULL)
- {
- while (p != NULL)
- {
- printf_s("%d", p->num);
- puts("");
- p = p->next;
- }
- }
- if (p == NULL)
- {
- while (q!=NULL )
- {
- printf_s("%d", q->num);
- puts("");
- q = q->next;
- }
- }
- }
- while (first != NULL)
- {
- q = first->next;
- delete first;
- first = q;
- }
- while (perviy != NULL)
- {
- q = perviy->next;
- delete perviy;
- perviy = q;
- }
- pechat(first);
- pechat(perviy);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement