function hotPotato (nameList,num){
var queue = new Queue();
for(var i=0; i<nameList.length;i++){
queue.enqueue(nameList[i]);
}
var eliminated = '';
while (queue.size()>1){
for(var i=0; i<num; i++){
queue.enqueue(queue.dequeue());
}
eliminated = queue.dequeue();
}
return queue.dequeue();
}
var names = ['john','jack','victor','sham','tom'];
var winner = hotPotato(names,3);
console.log('表演的人是:'+ winner);
柠檬酸钠
相关分类