简单约瑟夫环列表处理,也可以用递归更简单。
#include
#include
#include
typedef struct worker{
int data;
struct worker *next;
}linklist;
linklist* creat(int n){
linklist*head=NULL;
head=(linklist*)malloc(sizeof(linklist));
head;
head->next=NULL;
linklist*p=head;
int i;
for(i=0;idata=i+1;
p->next=q;
p=q;
}
p->next=head;
p=head;
return head;
}
int main()
{
int n;
scanf("%d",&n);
linklist*p;
p=creat(n);
int i,m;
scanf("%d",&m);
while(p->next!=p){
linklist*q=NULL;
for(i=1;i<=m;i++){
q=p;
p=p->next;
}
q->next=p->next;
p=p->next;
}
printf("%d",p->data);
return 0;}