const {CircleDoublyList} = require("ss-linked-list");
// 使用双向循环链表实现
function Josephus(n, start, k){
var numberArr = Array.from(new Array(n),(val,index)=>index+1);
var list = new CircleDoublyList(...numberArr);
var currentNode = list.getNode(start - 1);
var result = [];
while(n--){
for(var i = 0; i < k - 1; i++){
currentNode = currentNode.next;
}
result.push(currentNode.value);
currentNode.prev.next = currentNode.next;
currentNode.next.prev = currentNode.prev;
currentNode = currentNode.next;
}
return result;
}
Josephus(9, 1, 5);