数据结构与算法分析(C语言描述)66页 习题3.2
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
clock_t start,end;
typedef struct Node *PtrToLNode;
struct Node{
int data;
PtrToLNode next;
};
typedef PtrToLNode List;
List Read();
void PrintLots(List L,List P);
List Read()
{
List head,L;
L = (List)malloc(sizeof(List));
L->next = NULL;
head = L;
int LSize,i;
scanf("%d",&LSize);
if(LSize)
{
for(i = 0; i < LSize; i++)
{
List temp = (List)malloc(sizeof(List));
scanf("%d",&(temp->data));
temp->next = NULL;
L->next = temp;
L = temp;
}
}
return head;
}
void PrintLots(List L,List P)
{
List t1,t2;
t1 = L->next;
t2 = P->next;
int poi;
poi = 1;
while(t1 != NULL && t2 != NULL)
{
if(t2->data == poi++)
{
printf("%d\n",t1->data);
t2 = t2->next;
}
t1 = t1->next;
}
}
int main()
{
List L,P;
L = Read();
P = Read();
start = clock();
PrintLots(L,P);
end = clock();
printf("%f\n",(double)(end-start));
}
运行结果如下所示: