1.题目:
2.代码:
因为输入的两个链表是递增的,要求输出递减的,所以先归并再就地逆置
#include<iostream>
#include<stdlib.h>
//先进行归并,再进行就地逆置
using namespace std;
typedef struct node{
int value;
struct node *next;
}Node;
Node* PolyCreate(int elenum)
{
Node *head,*rear,*s;
head = (node*)malloc(sizeof(node));
rear = head;
for(int i = 0; i < elenum; i++)
{
int value;
cin >> value;
s = (node*)malloc(sizeof(node));
s->value = value;
rear->next = s;
rear = s;
}
rear->next = NULL;
return head;
}
Node* PolyMerge(Node *pa, Node *pb)
//线性表合并
{
Node *p,*q,*rear;
p = pa->next;
q = pb->next;
rear = pa; //最终归并的序列使用pa的空间,rear指向最终序列的尾端
rear->next = NULL;
while(p != NULL && q != NULL)
{
if(p->va