typedef struct p
{
int data;
struct p *next;
}node;
node *uniteList(node *first ,node *second)
{
node *head = NULL;
node *cur = NULL;
node *temp= NULL;
while (first && second)
{
//利用值的大小,挨个遍历
if (first->data < second->data)
{
temp = first;
first = first->next;
}
else
{
temp = second;
second= second->next;
}
if(head == NULL)
{
cur = temp;
head = cur;
}
else
{
cur->next = temp;
cur= temp;
}
}
if (first == NULL)
temp=second;
else
temp=first;
//挨个将每个结点插入一个新的链表
while (temp)
{
cur->next = temp;
temp=temp->next;
}
cur->next =NULL;
return head;
}
{
int data;
struct p *next;
}node;
node *uniteList(node *first ,node *second)
{
node *head = NULL;
node *cur = NULL;
node *temp= NULL;
while (first && second)
{
//利用值的大小,挨个遍历
if (first->data < second->data)
{
temp = first;
first = first->next;
}
else
{
temp = second;
second= second->next;
}
if(head == NULL)
{
cur = temp;
head = cur;
}
else
{
cur->next = temp;
cur= temp;
}
}
if (first == NULL)
temp=second;
else
temp=first;
//挨个将每个结点插入一个新的链表
while (temp)
{
cur->next = temp;
temp=temp->next;
}
cur->next =NULL;
return head;
}