#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
struct Man{
int num;
struct Man *next;
};
void LastRemain(int num,int count);
int main(){
LastRemain(13,3);
}
void LastRemain(int num,int count){
if(count==1){printf("the result is %d",num);return;}
struct Man * head=(struct Man *)malloc(sizeof(struct Man));
head->num=0;
struct Man *p=head,*q;
int i;
for(i=0;i<num;i++){
p->next=(struct Man *)malloc(sizeof(struct Man));
p=p->next;
p->num=i+1;
p->next=NULL;
}
p->next=head->next;
p=head->next;
q=head;
i=1;
while(p->next!=p){
if(i==count){
printf("delete %d\n",p->num);
q->next=p->next;
free(p);
p=q;
i=0;
}
i++;
q=p;
p=p->next;
}
printf("the last man is %d",p->num);
free(head);
free(p);
}
标签:13,struct,int,数数,next,num,退出,head,Man
From: https://www.cnblogs.com/zhongta/p/18211154