-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathDrumming and passing flowers.html
51 lines (50 loc) · 1.23 KB
/
Drumming and passing flowers.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<!DOCTYPE html>
<!--suppress ALL -->
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script>
let items = [];
let queue = {
enqueue:function (el) {
items.push(el);
},
delqueue:function () {
return items.shift();
},
queuelen:function () {
return items.length;
},
firstitem:function () {
return items[0];
},
isEmpty:function () {
return items.length = 0;
},
clearitems:function () {
items = [];
}
}
let hotPotato = function (nameList,num) {
for (let i = 0; i < nameList.length; i++) {
queue.enqueue(nameList[i]);
}
let eliminated = "";
while (queue.quequelen() > 1) {
for (let i = 0; i < num; i++) {
queue.enqueue(queque.delqueque());
}
eliminated = queue.delqueque();
console.log(eliminated + "被淘汰");
}
return queue.delqueque();
}
let people = ['a','b','c','d','e','f','g'];
let winner = hotPotato(people,10);
console.log(winner+"在本场击鼓传花胜出")
</script>
</body>
</html>