我正在尝试修改算法,但有些东西不是很好,因为我是 JavaScript/服务器/客户端问题的新手,所以我无法理解这个问题。
首先我应该修改服务器和客户端文件还是只修改客户端?这是我修改的客户端文件的一部分。你能解释一下我应该如何输入我的代码吗?
//nodeID = the id of the node in the circle
//inID = is the incomming id from the left node
//k=is the number of the leaders i want
//flag = checking if all leader have been elected
function processRound(message, round) {
if (round == 0) {
addToMessage("ID", nodeId);
}
else {
if (flag == 0) {
if (inId > nodeId) {
addToMessage("ID", inId);
}
else if (inId == nodeId) {
leader = true;
addLog("I am the leader");
}
else if (inId < nodeId) {
}
}
else if (flag == 1) {
if (inId == nodeId) {
}
else {
if (k < 0) {
leader = true;
k = k - 1;
}
else if (k > 0) {
flag = 0;
}
}
}