Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- struct Node {
- int n;
- struct Node *next;
- };
- struct Node *createNode(int n) {
- struct Node *elem = (struct Node *) malloc(sizeof(struct Node));
- elem->n = n;
- elem->next = NULL;
- return elem;
- };
- int main() {
- char end = ' ';
- int n;
- struct Node *head1;
- struct Node *head2;
- struct Node *head;
- struct Node *elem;
- struct Node *prev;
- for (int i = 0; i < 10; i++) {
- scanf("%d%c", &n, &end);
- elem = createNode(n);
- if (i == 0) {
- head1 = elem;
- prev = head1;
- continue;
- }
- prev->next = elem;
- prev = elem;
- if (end == '\n')
- break;
- }
- for (int i = 0; i < 10; i++) {
- scanf("%d%c", &n, &end);
- elem = createNode(n);
- if (i == 0) {
- head2 = elem;
- prev = head2;
- continue;
- }
- prev->next = elem;
- prev = elem;
- if (end == '\n')
- break;
- }
- head = createNode(head1->n);
- head1 = head1->next;
- struct Node *headALL = head;
- int i = 0;
- while ((head1 != NULL) || (head2 != NULL)){
- if(head2!=NULL){
- head->next = createNode(head2->n);
- head2 = head2->next;
- head = head->next;
- }
- if(head1!=NULL){
- head->next = createNode(head1->n);
- head1 = head1->next;
- head = head->next;
- }
- }
- while(headALL!=NULL){
- printf("%d ", headALL->n);
- headALL = headALL->next;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement