//Circular Linked List
//요셉의 문제
#include<stdio.h>
#include<stdlib.h>
typedef struct _node
{
int data;
struct _node* next;
}node;
node* head;
void step_del(int x);
void init_node(int x);
void main()
{
int n, step;
printf("사람의 수와 간격을 입력해 주세요 : ");
scanf("%d %d", &n, &step);
fflush(stdin);
init_node(n);
step_del(step);
}
void init_node(int x)
{
int i;
node* temp = (node*)malloc(sizeof(node));
head = temp;
temp->data = 1;
for(i=2 ; i<=x ; i++)
{
temp->next = (node*)malloc(sizeof(node));
temp = temp->next;
temp->data = i;
}
temp->next = head;
}
void step_del(int x)
{
int i;
node *a, *del;
a = head;
while(a != a->next)
{
for(i=0; i<x-1 ;i++)
a = a->next;
printf("%5d", a->next->data);
del = a->next;
a->next = a->next->next;
free(del);
}
printf("%5d\n",a->data);
free(a);
}