我想修改LCR算法,这样我就可以拥有多个领导者

时间:2013-11-08 16:03:43

标签: javascript algorithm

我正在尝试修改算法,但有些东西不能很好地工作,因为我是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;
                }
            }
        }

1 个答案:

答案 0 :(得分:0)

让我帮助你一点。 K = 3.你应该实施lcr算法3次,不包括找到的领导者。

相关问题