37.利用链表实现将两个有序队列A和B合并到有序队列H中,不准增加其他空间。

以升序为例:
while(a != NULL && b!= NULL)
{
if (a->data < b->data)
{
h->data = a->data;
a = a->next;
}
else if (a->data == b->data)
{
h->data = a->data;
a = a->next;
b = b->next;
}
else
{
h->data = b->data;
b = b->next
}
h = h->next;
}
if (a == NULL)
{
while (b != NULL)
{
h->data = b->data;
h = h->next;
b = b->next;
}
}
else 
{
while(a != NULL)
{
h->data = a->next;
h = h->next;
a = a->next;
}
}

你可能感兴趣的:(37.利用链表实现将两个有序队列A和B合并到有序队列H中,不准增加其他空间。)