struct node
{
int v;
node* next;
};
node* union_list(node* h1, node* h2)
{
if(!h1) return h2;
if(!h2) return h1;
node* cur = new node;
node* t1 = h1, *t2 = h2;
while(h1&&h2)
{
if(h1->v <= h2->v)
{
cur->next = h1;
cur = cur->next;
h1 = h1->next;
}else{
cur->next = h2;
cur = cur->next;
h2 = h2->next;
}
}
if(!h1) cur->next = h2;
else cur->next = h1;
return t1->v <= t2->v ? t1 : t2;
}
合并有序链表
最新推荐文章于 2024-09-18 18:16:42 发布