#include <stdio.h>

#include <stdlib.h>


typedef struct node {

int data;

struct node* next;

}node;

typedef struct Arrlist {

node* head;

node* cur;

node* before;

}alist;


void listinit(alist* list) {

list->head = NULL;

list->cur = NULL;

list->before = NULL;

}

void listinsert(alist* list, int data) {

node* newNode = (node*)malloc(sizeof(node));

newNode->data = data;

if (list->head == NULL) {

newNode->next = newNode;

list->cur = newNode;

}

else {

list->cur->next = newNode;

newNode->next = list->head;

list->before = list->cur;

list->cur = newNode;

}

}

int listdelete(alist* list, int d) {

node* delNode;

int del;

for (int i = 0; i < d; i++) {

list->cur = list->cur->next;

}

delNode = list->cur;

del = delNode->data;

list->before->next = list->cur->next;

free(delNode);

return del;

}

int main() {

alist list;

listinit(&list);

int N, K;

scanf("%d %d", &N, &K);

for (int i = 1; i <= N; i++) {

listinsert(&list, i);

}

printf("<");

for (int i = 1; i <= N; i++) {

if (i == N) {

printf("%d", listdelete(&list, N-1*K));

}

else {

printf("%d, ", listdelete(&list, K*i));


}

}

printf(">");

}


분명 before에다가 이전 값을 줬잖아


근데 왜 NULL이야


요세푸스 푸는데 그냥 큐로 풀까