数据结构 约瑟夫环 源程序

来源:百度知道 编辑:UC知道 时间:2024/05/05 23:06:47

/*Joseph*/
struct Jo{
int num;
int secret;
struct Jo *next;
}*Jhead;
int t=0;

/*该函数用于建立Joseph循环链表*/
struct Jo * createl(struct Jo *Jhead){
struct Jo *p=Jhead,*r;
int t=0;
while(1){
r=(struct Jo *)malloc(sizeof(struct Jo));
printf("please input number and secret \n");
printf("number and secret :");
scanf("%d%d",&(r->num),&(r->secret));
if(r->num<=0){
free(r);
break;
}
else{
if(t==0){
Jhead=p=r; t=10;
}
else{
p->next=r;p=r;
}
}
}
p->next=Jhead;
clrscr();
return Jhead;
}

/*该函数完成Joseph环中的循环,至到剩余一个人*/
void Circle(struct Jo *Jhead,int