给定两个递增排序的链表,请合并这两个链表并使新链表中的节点仍然是递增排序的,合并后的链表中不能包含重复的元素。
本题要求用链表实现。
输入
两个递增排序的链表,其中所有元素均为整数,每个表均以数字-1
作为输入结束标志。
输出
在单独的行中输出按要求合并后的结果。
示例输入1
1 2 4 -1
1 3 4 -1
示例输出1
1 2 3 4
输入示例2
1 -1
1 -1
示例输出2
1
[代码实现]
#include<stdio.h>
#include<stdlib.h>
short InitHeadNode(struct Node* &, struct Node* &);
void Traversal(struct Node* &);
short RearInsert(struct Node* &, struct Node* &, short);
void LinkListMerge(struct Node* &, struct Node* &, struct Node* &);
void RemoveRedundancy(struct Node* &);
/* 链表结点定义 */
struct Node
{
short data;
struct Node *next;
};
int main()
{
struct Node *head1;
struct Node *rear1;
struct Node *head2;
struct