java 为什么没有函数调用_为什么函数没有调用?

我在C写下面的程序

该程序是一个邻接矩阵,它要求用户在节点之间设置连接,然后检查节点A和节点B之间是否存在连接 .

# include

# include

#define N 11

#define FALSE 0

#define TRUE 1

typedef int adj_mat[N][N]; /*defining adj_mat */

int path (adj_mat A, int u, int v);

主要功能要求用户制作有向图,然后要求用户输入两个节点以检查它们是否存在节点A和节点B之间的连接 .

int main()

{

adj_mat Matrix; /*intializing a new graph adjacency matrix.

on this moment nodes are disconnected every cell contains zero */

int dadnode, sonnode; /*intializing dad node and son node*/

printf("Hello. Enter now the pairs of connected nodes.\n");

printf("enter EOF after finishing of connecting all the nodes\n");

do { /*here user enter the nodes to connect */

printf("Enter the number of first node\n");

scanf("%d", &dadnode);

printf("Enter the number of second node\n");

scanf("%d", &sonnode);

if ((dadnode < sonnode) && (sonnode <= N) && (dadnode > 0)) /*checking if nodes are legal*/

Matrix[dadnode][sonnode] = 1; /*if legal - connect*/

} while ( (dadnode != EOF ) && (sonnode != EOF)); /*until user enter EOF */

printf("Now enter u and v nodes to check if exists way from u node to we node\n");

/*here user enter the nodes to check */

printf("Enter the number of u node\n");

scanf("%d", &dadnode);

printf("Enter the number of v node\n");

scanf("%d", &sonnode);

if ((dadnode < sonnode) && (sonnode <= N) && (dadnode > 0)) /*checking if nodes are legal*/ {

if( path(Matrix,dadnode,sonnode) == TRUE ) /*if exisits way from u to v*/

printf ("Exists way from node u to node v ");

}

else printf ("Not exists way from node u to node v ");

}

如果存在从u(dad节点)到v(子节点)的存在方式,则以下函数返回TRUE,否则返回FALSE

int path (adj_mat A, int u, int v) {

if (v >= u) /*no sense to check if dad node yonger than son node or dad of himself */

return FALSE;

int nodenum; /*number of node*/

/* "nodenum = v - 1" because node v cannot be son of node >= v */

for(nodenum = v - 1; nodenum > 0; nodenum-- ) {

if (A[nodenum][v] == TRUE) /*dad detected*/

{

if (nodenum == u) {

return TRUE; //complete

} else if (path (A, u, nodenum)) {

return TRUE; //maybe dad is a node that we are looking for (recursion)

}

}

}

return FALSE; /*all parents of v node were cheked and noone of them isnt u node*/

}

最后,我在gdb(ubuntu)中运行它 .

do { /*here user enter the nodes to connect */

printf("Enter the number of first node\n");

scanf("%d", &dadnode);

printf("Enter the number of second node\n");

scanf("%d", &sonnode);

if ((dadnode < sonnode) && (sonnode <= N) && (dadnode > 0)) {/*checking if nodes are legal*/

Matrix[dadnode][sonnode] = 1; /*if legal - connect*/

}

} while ( (dadnode != EOF ) && (sonnode != EOF)); /*until user enter EOF */

为什么当我尝试通过按Ctrl d来停止此循环(从主函数)时,循环将继续并且仅在找到一对数字之后停止,其中一个数字为-1?

好的,输入“-1”然后main函数应该调用path()函数来检查节点a和节点b是否连接 . 如果是,那么它应该根据路径的结果(Matrix,dadnode,sonnode)输出一条消息 .

但是,我收到消息“程序正常退出”,而不是这种行为 . 为什么我收到此消息?

main函数是否甚至调用path()函数?我不确定我的代码中的错误是什么......

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值