我刚学的啊 现学现卖 没准会有大的bug
程序代码:
程序代码:#include <stdio.h>
#include <malloc.h>
#define N 9
typedef struct data
{
int value;
struct data* next;
}tdata,*pdata;
void prnlist(pdata head)
{
pdata pfirst=head->next;
while(pfirst!=NULL)
{
printf("%d ",pfirst->value);
pfirst=pfirst->next;
}
printf("\n");
}
int main(int argc, char* argv[])
{
pdata head1,pfirst1,psecond1;
pfirst1=(pdata)malloc(sizeof(tdata));
head1=pfirst1;
head1->value=0;
head1->next=NULL;
psecond1=pfirst1;
int i;
printf("请录入第一组数据 :\n");
for(i=0;i<N;i++)
{
pfirst1=(pdata)malloc(sizeof(tdata));
scanf("%d",&pfirst1->value);
pfirst1->next=NULL;
psecond1->next=pfirst1;
psecond1=pfirst1;
}
printf("请录入第二组数据:\n");
pdata pfirst2=(pdata)malloc(sizeof(tdata));
pdata head2=pfirst2;
head2->value=0;
head2->next=NULL;
pdata psecond2=pfirst2;
for(i=0;i<N;i++)
{
pfirst2=(pdata)malloc(sizeof(tdata));
scanf("%d",&pfirst2->value);
pfirst2->next=NULL;
psecond2->next=pfirst2;
psecond2=pfirst2;
}
printf("你所录入的两组数据如下:\n");
prnlist(head1);
prnlist(head2);
printf("共有数据如下:\n");
for(pfirst1=head1->next;pfirst1!=NULL;pfirst1=pfirst1->next)
{
for(pfirst2=head2->next;pfirst2!=NULL;pfirst2=pfirst2->next)
{
if(pfirst2->value==pfirst1->value) printf("%d ",pfirst2->value);
}
}
printf("\n");
//free(head1);
//free(head2);
return 0;
}
/*
请录入第一组数据 :
1 2 3 4 5 6 7 8 9
请录入第二组数据:
2 3 4 5 6 7 8 9 10
你所录入的两组数据如下:
1 2 3 4 5 6 7 8 9
2 3 4 5 6 7 8 9 10
共有数据如下:
2 3 4 5 6 7 8 9
*/[此贴子已经被作者于2017-3-23 22:17编辑过]

DO IT YOURSELF !







