在codebolcks里面运行能够正常出结果,但是不是return 0,return的数字和输入的n有关请问我的代码有问题吗?
#include
#include
struct child
{
int num;
struct child *pre;
struct child *next;
};
int main()
{
int n,k;
scanf("%d %d",&n,&k);
struct child *current,*prev,*home;
current = (struct child *) malloc(sizeof(struct child));
current->num=1;
prev=current;
home=current;
int i,roll=1;
for (i=1; i
current = (struct child *) malloc(sizeof(struct child));
if (current == NULL) {
printf("wrong!");
}
current->num=1+i;
current->pre=prev;
prev->next=current;
prev=current;
}
prev->next=home;
home->pre=prev;
int num,mod;
while (roll<=n)
{
if (roll>1) {
putchar(' ');
}
num=roll+k-1;
mod=num%(n-roll+1);
while (mod>0)
{
home=home->next;
//printf("%p",home);
mod--;
}
printf("%d",home->num);
prev=home->pre;
prev->next=(home->next);
prev=home;
home=home->next;
free(prev);
roll++;
}
}
运行结果如图:return 6的部分求解释