求大神看看我的约瑟夫环程序哪里出错了
#include<stdio.h>#include<stdlib.h>
typedef struct node
{ int num;
int sm;
struct node *next;
}JOS;
JOS *creat();
void outs(JOS *h,int m);
main()
{ int m;JOS *h;
h=creat();
printf("\n enter the begin secret code,m=(m>1)");scanf("%d",&m);
outs(h,m);
}
JOS *creat()
{ int i=0,mi;
JOS *new,*pre,*h;
h=(JOS *)malloc(sizeof(JOS));
h->link=h;
pre=h;
printf("\n个人密码=?");scanf("%d",&mi);
while(mi !=-111)
{ new=(JOS *)malloc(sizeof(JOS));
i++;new->num=i;new->sm=mi;
new->link=h;
pre->link=new;
pre=new;
printf("\n个人密码=?");scanf("%d",&mi);
}
pre->link=h->link;free(h);
h=pre->link;return(h);
}
void outs(JOS *h,int m)
{ int i;JOS *q=h,p;
printf("\n ");
while(q->link!=q)
{ for(i=1;i<m;i++){p=q;q=q->link;}
printf("%6d %6d ",q->num,q->sm);
p->link=q->link;free(q);
q=p->link;
}
printf("%6d %6d \n",q->num,q->sm);
free(q);
}