#include<bits/stdc++.h>
using namespace std;
typedef struct Node
{
int data;
struct Node * next;
}*node;
struct Node* createlist()
{
struct Node*headNode = (struct Node*)malloc(sizeof(struct Node));
headNode->next = NULL;
headNode->data = NULL;
return headNode;
}
struct Node* createNode(int data)
{
struct Node*newNode = (struct Node*)malloc(sizeof(struct Node));
newNode->next = NULL;
newNode->data = data;
return newNode;
}
void insertByTail(struct Node*headNode,int data)
{
struct Node*newNode = createNode(data);
struct Node*tailNode = headNode;
while(tailNode->next != NULL)
{
tailNode = tailNode->next;
}
tailNode->next = newNode;
}
void printList(node list)
{
node i = list->next;
for(;i != NULL; i = i->next)
{
printf("%d ", i->data);
}
puts("");
}
node merge(node A, node B)
{
node tailNode = A;
while(tailNode->next != NULL)
{
tailNode = tailNode->next;
}
tailNode->next = B->next;
return A;
}
int main()
{
node A = createlist();
node B = createlist();
int i;
printf("输入链表A的数据:\n");
while(cin >> i)
{
insertByTail(A, i);
if(cin.get() == '\n')
break;
}
printf("输入链表B的数据:\n");
while(cin >> i)
{
insertByTail(B, i);
if(cin.get() == '\n')
break;
}
printf("合并后链表C为:\n");
node C = merge(A, B);
printList(C);
return 0;
}
balabalabalabalabalabalabalabalabalabalabalabalabalabala