gpt4 book ai didi

c++ - Node是什么样的类型?

转载 作者:太空宇宙 更新时间:2023-11-04 07:39:06 24 4
gpt4 key购买 nike

我必须使用这个参数执行 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);

}


}

}

最佳答案

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

关于c++ - Node是什么样的类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5892016/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com