Node 是什么样的类型?
我必须使用确切的此参数执行 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您创建的结构或类必须是 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.