#include<stdlib.h> #define N 10 typedef struct jos_list{ int count; struct jos_list *next; }linknode; typedef linknode *linklist;
linklist creat_list(void) { linklist head,p,q; q=head=(linklist)malloc(sizeof(linknode)); head->count=1; head->next=NULL; while(q->count<N) { p=(linklist)malloc(sizeof(linknode)); p->count=q->count+1; p->next=q->next; q->next=p; q=p; } q->next=head; return head; }
int jos_find(linklist a,int n) { linklist p,q=a; int i; while(q->next!=q) { for(i=1;i<n;i++) { p=q; q=q->next; } p->next=q->next; free(q); q=p->next; }
return q->count; }
main() { linklist a,head; int m,i,k; head=creat_list(); for(i=1;i<=N;i++) { printf("%3d",head->count); head=head->next; } printf("\n"); printf("di ji ge kai shi bao?"); scanf("%d",&m); printf("bao ji de chu lie:"); scanf("%d",&k); printf("\n");
for(i=1;i<m;i++) head=head->next; m=jos_find(head,k);- printf("zhui hou liu xia de shi :%d\n",m); }
[此贴子已经被作者于2004-11-07 12:05:25编辑过]