1 // the Create function pointer with a pass way not to create lists? 2 . 3 #include <stdio.h> . 4 #include <stdlib.h> . 5 struct the Person . 6 { . 7 int NUM; . 8 struct the Person * Next; . 9 }; 10 . 11 int main () 12 is { 13 is struct the Person * P = NULL ; 14 int n-, m; 15 Scanf ( " % D% D " , & n-, & m); 16 void Create ( struct the Person *,int ); // with struct Person * create (int); can . 17 int Yue ( struct the Person *, int , int ); 18 is Create (P, n-); // to p = create (n); can 19 printf ( " % d \ the n- " , Yue (the p-, the n-, m)); 20 return 0 ; 21 } 22 23 void the create ( struct the Person the p-*, int the n-) // question: Why in this way can not be successfully created The new list? 24 { 25 struct Person *p1,*p2; //改为:struct Person *head,*p1,*p2; 26 p1=(struct Person *)malloc(sizeof(Person)); 27 int i=0; 28 while(i<n) 29 { 30 i++; 31 p1->num=i; 32 if(i==1) p=p2=p1; //改为:if(i==1) head=p2=p1; 33 else 34 { 35 p2->next=p1; 36 p2=p1; 37 } 38 p1=(struct Person *)malloc(sizeof(Person)); 39 } 40 p2->next=NULL; 41 free(p1); 42 p1=NULL; 43 //加一行:return head; 44 } 45 46 int Yue(struct Person* p,int n,int m) 47 { 48 int i=0,j=1,k=0; 49 struct Person *q,*r; 50 q=r=p; 51 while(k<n-1) 52 { 53 i++; 54 j++; 55 56 if(i!=1) r=r->next; 57 if(r==NULL) r=p; 58 59 q=q->next; 60 if(q==NULL) q=p; 61 62 if(j==m) 63 { 64 j=1; 65 k++; 66 if(q==p) 67 { 68 p=p->next; 69 q->next=NULL; 70 free(q); 71 q=p; 72 } 73 else if(q->next==NULL) 74 { 75 r->next=NULL; 76 free(q); 77 q=p; 78 } 79 else 80 { 81 r->next=q->next; 82 free(q); 83 q=r->next; 84 } 85 } 86 } 87 return q->num; 88 }