//给链表L和P,升序排列的整数,写函数PrintLost打印L中由P指定的位置上的元素
#include<stdio.h>
#include<stdlib.h>
struct Lian *Create();
void PrintLost(struct Lian *L,struct Lian *P);
struct Lian
{
int data;
struct Lian *next;
};
int main()
{
struct Lian *L,*P;
L=Create();
P=Create();
PrintLost(L,P);
return 0;
}
struct Lian *Create()
{
struct Lian *head=NULL,*p,*p1;
p=(struct Lian *)malloc(sizeof(struct Lian));
scanf("%d",&p->data );
p->next =NULL;
while(p->data !=-1)
{
if(head==NULL)
{
head=p;
p1=p;
}
else
{
p1->next =p;
p1=p;
}
p=(struct Lian *)malloc(sizeof(struct Lian));
scanf("%d",&p->data );
p->next =NULL;
}
return head;
}
void PrintLost(struct Lian *L,struct Lian *P)
{
struct Lian *l,*p;
l=L;
p=P;
int k=0,j;
while(p!=NULL)
{
k=p->data-k ;
for(j=1;j<k;j++)
{
l=l->next ;
}
printf("%3d",l->data );
l=l->next ;
p=p->next ;
}
putchar('\n');
}