//Dev c++

#include<stdio.h>

#include<malloc.h>

#include<string.h>//调用putchar函数

typedef struct stu{

int num;

struct stu*next;

}stu,*pointer;

int main()

{

int i,n,m,count;

pointer p,q,r;

r=p=q=(pointer)malloc(sizeof(pointer));

p->num=1;p->next=NULL;//无头结点

printf("Input n and m:");//m为步长

scanf("%d%d",&n,&m);

for(i=2;i<=n;i++)//建立链表

{

p=(pointer)malloc(sizeof(pointer));

p->num=i;

r->next=p;

r=r->next;

}

p->next=q;//循环链表

printf("出圈顺序为:\n");

for(i=1,count=0;count<n-1;)//删除(n-1)个数

{

if(i==m)

{

printf("%d ",q->num);

p->next=q->next;//删除q节点

free(q);

q=p->next;

count++;

i=1;

}

else

{

p=p->next;

q=q->next;

i++;//i++不能写在for循环内部

}

}

printf("%d ",p->num);

putchar('\n');

system("pause");

return 0;

}