{"size": 675, "ext": "js", "max_stars_repo_path": "Coding-math/queue/del_ring.js", "max_stars_repo_name": "xtzx/-", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Coding-math/queue/del_ring.js", "max_issues_repo_name": "xtzx/-", "max_issues_repo_issues_event_min_datetime": "2021-03-11T01:34:47.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-27T08:36:31.000Z", "max_forks_repo_path": "Coding-math/queue/del_ring.js", "max_forks_repo_name": "xtzx/ProjectOfLearn", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 10, "max_forks_count": null, "avg_line_length": 18.2432432432, "max_line_length": 63, "alphanum_fraction": 0.5614814815}
/**
 * 约瑟夫环
 * 有一个数组a[1000]存放0--1000;要求每隔二个数删掉一个数，
 * 到末尾时循环至开头继续进行，求最后一个被删掉的数的原始下标位置
 */

Queue = require('./myqueue')

function del_ring(arr_list) {

    var queue = new Queue.Queue();

    for (var i = 0; i < arr_list.length; i++) {
        queue.enqueue(arr_list[i]); // 把数组里的元素都放入到队列中
    }

    var index = 0;

    while (queue.size() != 1) {
        var item = queue.dequeue(); // 弹出一个元素,判断是否需要删除
        index += 1;
        if (index % 3 != 0) { // 每隔两个就要删除掉一个,那么不是被删除的元素就放回到队列尾部
            queue.enqueue(item);
        }
    }

    return queue.head();
};


var arr_list = [];
for (var i = 0; i < 3; i++) {
    arr_list.push(i);
}


console.log(del_ring(arr_list));