Node 是什么样的类型?

发布于 2024-11-05 07:38:14 字数 4012 浏览 1 评论 0原文

我必须使用确切的此参数执行 void initRT(Node *n;) 。我应该怎么办??

struct RtPkt{
    int sourceid;
    int destid;
    int mincost[5];
};

struct  dr_table {
    int costs[5];
    int nexthop[5];
};


int connectcosts[NUMNODES][NUMNODES];

/* Setup the network costs */
void initcosts() {
static int initialized = 0;
if (!initialized) {
    /* initialize by hand since not all compilers allow array initilization */
    connectcosts[0][1] = connectcosts[1][0] = 1; // x0
    connectcosts[1][2] = connectcosts[2][1] = 1; // x1
    connectcosts[2][3] = connectcosts[3][2] = 2; // x2
    connectcosts[0][3] = connectcosts[3][0] = 6; // x3
    connectcosts[1][4] = connectcosts[4][1] = 5; // x4
    connectcosts[0][2] = connectcosts[2][0] = 4; // x5
    connectcosts[3][4] = connectcosts[4][3] = 1; // x6

    /* Not connected nodes */
    connectcosts[0][4] = connectcosts[4][0] = connectcosts[1][3] =
        connectcosts[3][1] = connectcosts[2][4] = connectcosts[4][2] =
        999;

    /* Loopback links */
    connectcosts[0][0] = connectcosts[1][1] = connectcosts[2][2] =
        connectcosts[3][3] = connectcosts[4][4] = 0;
    }
}

/**
 * H synarthsh ayth pairnei san orisma enan deikth se Node. To pedio
 * id ths domhs prepei na einai arxikopoihmeno sto index toy komboy (p.x.
 * 0 gia to node 0, 1 gia to node 1, kok) H synarthsh ayth prepei na
 * arxikopoihsei to routing table toy komboy me bash ton pinaka connectcosts
 * poy orizetai kai arxikopoieitai sto node.c kai katopin na steilei ena
 * katallhlo RtPkt se oloys toys geitonikoys komboys toy node.
 */

 struct RtPkt packet;
void initRT(Node *n;) {
    int i,j;
packet.sourceid=i;
for (i=0;i<5;i++)
    for (j=0;j<5;j++)
        {
        n->costs[i]=connectcosts[i][j];
    }
    packet.mincost[i]=n.costs[i];
    if (packet.sourceid=0)
        {

            n->nexthop[0]=0;
            n->nexthop[1]=1;
            n->nexthop[2]=2;
            n->nexthop[3]=3;
            n->nexthop[4]=999;

            tolayer2(packet);
            packet.destid=1;
            tolayer2(packet);

            packet.destid=2;
            tolayer2(packet);

            packet.sourceid=3;
            tolayer2(packet);
        }
    else if (packet.sourceid=1)
        {
            n->nexthop[0]=0;
            n->nexthop[1]=1;
            n->nexthop[2]=2;
            n->nexthop[3]=999;
            n->nexthop[4]=4;

            tolayer2(packet);
            packet.destid=0;
            tolayer2(packet);

            packet.destid=2;
            tolayer2(packet);

            packet.sourceid=4;
            tolayer2(packet);
        }
    else if (packet.sourceid=2)
        {
                n->nexthop[0]=0;
                n->nexthop[1]=1;
                n->nexthop[2]=2;
                n->nexthop[3]=3;
                n->nexthop[4]=999;

                tolayer2(packet);
                packet.destid=0;
                tolayer2(packet);

                packet.destid=1;
                tolayer2(packet);

                packet.sourceid=3;
                tolayer2(packet);
        }
    else if (packet.sourceid=3)
        {
                n->nexthop[0]=0;
                n->nexthop[1]=999;
                n->nexthop[2]=2;
                n->nexthop[3]=3;
                n->nexthop[4]=4;

                tolayer2(packet);
                packet.destid=0;
                tolayer2(packet);

                packet.destid=2;
                tolayer2(packet);

                packet.sourceid=4;
                tolayer2(packet);
        }
    else if (packet.sourceid=4)
        {
                n->nexthop[0]=0;
                n->nexthop[1]=999;
                n->nexthop[2]=2;
                n->nexthop[3]=3;
                n->nexthop[4]=4;

                tolayer2(packet);
                packet.destid=1;
                tolayer2(packet);

                packet.destid=3;
                tolayer2(packet);

        }


    }

}

i have to do the void initRT(Node *n;) with exact this parameter. what should i do??

struct RtPkt{
    int sourceid;
    int destid;
    int mincost[5];
};

struct  dr_table {
    int costs[5];
    int nexthop[5];
};


int connectcosts[NUMNODES][NUMNODES];

/* Setup the network costs */
void initcosts() {
static int initialized = 0;
if (!initialized) {
    /* initialize by hand since not all compilers allow array initilization */
    connectcosts[0][1] = connectcosts[1][0] = 1; // x0
    connectcosts[1][2] = connectcosts[2][1] = 1; // x1
    connectcosts[2][3] = connectcosts[3][2] = 2; // x2
    connectcosts[0][3] = connectcosts[3][0] = 6; // x3
    connectcosts[1][4] = connectcosts[4][1] = 5; // x4
    connectcosts[0][2] = connectcosts[2][0] = 4; // x5
    connectcosts[3][4] = connectcosts[4][3] = 1; // x6

    /* Not connected nodes */
    connectcosts[0][4] = connectcosts[4][0] = connectcosts[1][3] =
        connectcosts[3][1] = connectcosts[2][4] = connectcosts[4][2] =
        999;

    /* Loopback links */
    connectcosts[0][0] = connectcosts[1][1] = connectcosts[2][2] =
        connectcosts[3][3] = connectcosts[4][4] = 0;
    }
}

/**
 * H synarthsh ayth pairnei san orisma enan deikth se Node. To pedio
 * id ths domhs prepei na einai arxikopoihmeno sto index toy komboy (p.x.
 * 0 gia to node 0, 1 gia to node 1, kok) H synarthsh ayth prepei na
 * arxikopoihsei to routing table toy komboy me bash ton pinaka connectcosts
 * poy orizetai kai arxikopoieitai sto node.c kai katopin na steilei ena
 * katallhlo RtPkt se oloys toys geitonikoys komboys toy node.
 */

 struct RtPkt packet;
void initRT(Node *n;) {
    int i,j;
packet.sourceid=i;
for (i=0;i<5;i++)
    for (j=0;j<5;j++)
        {
        n->costs[i]=connectcosts[i][j];
    }
    packet.mincost[i]=n.costs[i];
    if (packet.sourceid=0)
        {

            n->nexthop[0]=0;
            n->nexthop[1]=1;
            n->nexthop[2]=2;
            n->nexthop[3]=3;
            n->nexthop[4]=999;

            tolayer2(packet);
            packet.destid=1;
            tolayer2(packet);

            packet.destid=2;
            tolayer2(packet);

            packet.sourceid=3;
            tolayer2(packet);
        }
    else if (packet.sourceid=1)
        {
            n->nexthop[0]=0;
            n->nexthop[1]=1;
            n->nexthop[2]=2;
            n->nexthop[3]=999;
            n->nexthop[4]=4;

            tolayer2(packet);
            packet.destid=0;
            tolayer2(packet);

            packet.destid=2;
            tolayer2(packet);

            packet.sourceid=4;
            tolayer2(packet);
        }
    else if (packet.sourceid=2)
        {
                n->nexthop[0]=0;
                n->nexthop[1]=1;
                n->nexthop[2]=2;
                n->nexthop[3]=3;
                n->nexthop[4]=999;

                tolayer2(packet);
                packet.destid=0;
                tolayer2(packet);

                packet.destid=1;
                tolayer2(packet);

                packet.sourceid=3;
                tolayer2(packet);
        }
    else if (packet.sourceid=3)
        {
                n->nexthop[0]=0;
                n->nexthop[1]=999;
                n->nexthop[2]=2;
                n->nexthop[3]=3;
                n->nexthop[4]=4;

                tolayer2(packet);
                packet.destid=0;
                tolayer2(packet);

                packet.destid=2;
                tolayer2(packet);

                packet.sourceid=4;
                tolayer2(packet);
        }
    else if (packet.sourceid=4)
        {
                n->nexthop[0]=0;
                n->nexthop[1]=999;
                n->nexthop[2]=2;
                n->nexthop[3]=3;
                n->nexthop[4]=4;

                tolayer2(packet);
                packet.destid=1;
                tolayer2(packet);

                packet.destid=3;
                tolayer2(packet);

        }


    }

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏夜暖风 2024-11-12 07:38:14

您创建的结构或类必须是 Node 的子类,那么将该类型的对象传递给 initptr 函数应该没有问题。

The struct or class that you create has to be a subclass of Node, then you should have no problems passing an object of that type to the initptr function.

携余温的黄昏 2024-11-12 07:38:14
void yourcode()
{

    // declare an instance of a node on the stack
    Node n;

    // pass it by pointer to the initptr function
    initptr(&n);

}
void yourcode()
{

    // declare an instance of a node on the stack
    Node n;

    // pass it by pointer to the initptr function
    initptr(&n);

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文