#include <stdio.h>
#include <stdlib.h>
typedef struct node *link;
typedef struct node
{
int xh,mm;
link next;
}Node;
typedef struct llist *List;
typedef struct llist{link first;}Llist;
List ListInit(int n)
{
List L=(List)malloc(sizeof(List));
link x=(link)malloc(sizeof(link));
int i,t;
link p;
L->first=x;
x->xh=1;
printf("(%d)Please Input the code of the first person:");
scanf("%d",&t);
if(t<0){
printf("ERROR!\nPlease Input the code of the First person again:");
scanf("%d",&t);
}
else x->mm=t;
x->next=0;
p=x;
for(i=2;i<=n;i++)
{
link x=(link)malloc(sizeof(link));
p->next=x;
x->xh=i;
printf("(%d)Please Input the code of the Next person:",i);
scanf("%d",&t);
if(t<0){
printf("ERROR!\n(%d)Please Input the code of the Next person again:",i);
scanf("%d",&t);
}
else x->mm=t;
x->next=0;
p=p->next;
}
p->next=L->first;
return L;
}
void Joseph(link p,int m,int n)
{
int i,k;
if(m!=1){
for(i=1;i<m-1;i++){p=p->next;}
printf("\t%d",p->next->xh);
k=p->next->mm;
p->next=p->next->next;
p=p->next;
n--;
if(n>=1) Joseph(p,k,n);
}
else{
link q;
printf("%d\t",p->xh);
k=p->mm;
q=p->next;
while(q->next!=p) q=q->next;
q->next=p->next;
p=p->next;
n--;
if(n>=1) Joseph(p,k,n);
}
}
void main()
{
int n,m;
List L;
printf("Please Input the Total Number of the People:");
scanf("%d",&n);
L=ListInit(n);
printf("Please Set a Number:");
scanf("%d",&m);
if(m<0){
printf("ERROR! Please Input the code again:");
scanf("%d",&m);
}
printf("The order is:");
Joseph(L->first,m,n);
}
ysf.rar_M?n
版权申诉
135 浏览量
2022-09-20
16:31:38
上传
评论
收藏 718B RAR 举报
寒泊
- 粉丝: 75
- 资源: 1万+