回复 3楼 renkejun1942
我还真尝试过去追递归 后来放弃了
#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; }可是这样改 就完蛋了 没链了