这个程序有一点看不懂
/*现有两个带表头节点的单链表la和lb,
此两个表本身无相同元素存在,
la表递增有序,lb表递减有序,
且lb表中的元素包含在la表中连续的某一部分,
设计一个算法找出这部分元素在la的位置,并将它们逆置,使之与lb表中的序相同.*/
#include <iostream.h>
#include <malloc.h>
typedef int elemtype;
typedef struct linknode
{
elemtype data;
struct linknode *next;
}nodetype;
nodetype *create()
{
elemtype d;
nodetype *h=NULL,*s,*t;
int i=1;
cout << "建立一个单链表" << endl;
while (1)
{
cout << " 输入第" << i << "节点data域值:";
cin >> d;
if (d==0) break;
if (i==1)
{
h=(nodetype*)malloc(sizeof(nodetype));
h->data=d;h->next=NULL;t=h;
}
else
{
s=(nodetype *)malloc(sizeof(nodetype));
s->data=d;s->next=NULL;t->next=s;
t=s;
}
i++;
}
return h;
}
void disp(nodetype *h)
{
nodetype *p=h;
cout << "输出一个单链表:" << endl << " ";
if (p==NULL) cout << "空表";
while (p!=NULL)
{
cout << p->data << " ";p=p->next;
}
cout << endl;
}
nodetype *findplace(nodetype *la,nodetype *lb)
{
nodetype *pa,*pb=lb,*ra,*rb=lb;
while(rb->next!=NULL)
rb=rb->next;
pa=la->next;ra=la;
while (pa!=NULL && pa->data!=rb->data)
{
ra=pa;
pa=pa->next;
}
cout << "ra=" << ra->data << endl;
ra->next=lb->next;
pb=lb->next;
while (pa!=NULL && pa->data!=pb->data){
pa=pa->next;
rb->next=pa->next;}
return la->next;
}
void main()
{
nodetype *la,*lb,*lc,*t;
la=create();
lb=create();
disp(la);
disp(lb);
t=(nodetype *)malloc(sizeof(nodetype));
t->next=la,la=t;
t=(nodetype *)malloc(sizeof(nodetype));
t->next=lb;lb=t;
lc=findplace(la,lb);
disp(lc);
}
----------------------------------------------------
ra->next=lb->next;
pb=lb->next;
while (pa!=NULL && pa->data!=pb->data){
pa=pa->next;
rb->next=pa->next;}
这几行我看不懂,lb->next应该是NULL了,怎么ra->next怎么还要等于NULL了?