node *mergelink(node *p,node *q){node *h,*r;h = (node*) malloc (sizeof(node));h->next = NULL;r = h;while (p = NULL && q = NULL){if (p->data data){r->next = p;r = p;p = p->next;}else{r->next = q;r = q;q = q->next;}}if (p == NULL)r->next = q;if (q == N
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/24 07:17:36
node *mergelink(node *p,node *q){node *h,*r;h = (node*) malloc (sizeof(node));h->next = NULL;r = h;while (p = NULL && q = NULL){if (p->data data){r->next = p;r = p;p = p->next;}else{r->next = q;r = q;q = q->next;}}if (p == NULL)r->next = q;if (q == N
node *mergelink(node *p,node *q)
{
node *h,*r;
h = (node*) malloc (sizeof(node));
h->next = NULL;
r = h;
while (p = NULL && q = NULL)
{
if (p->data data)
{
r->next = p;
r = p;
p = p->next;
}
else
{
r->next = q;
r = q;
q = q->next;
}
}
if (p == NULL)
r->next = q;
if (q == NULL)
r->next = p;
p = h->next;
h = h->next;
free(p);
return h;
}
刚学的,
node *mergelink(node *p,node *q){node *h,*r;h = (node*) malloc (sizeof(node));h->next = NULL;r = h;while (p = NULL && q = NULL){if (p->data data){r->next = p;r = p;p = p->next;}else{r->next = q;r = q;q = q->next;}}if (p == NULL)r->next = q;if (q == N
这个是归并排序的 merge 过程的链表实现算法
该方法实现的功能是,将两个已排序链表(分别用p, q表示相应的头指针)合并(merge)成一个有序链表
算法本身很简单,如果不明白,建议先熟悉下归并排序过程