假设邻接矩阵为adj_matrix,顶点序号从0开始,则代码如下:

int degree(int adj_matrix[][MAX_V], int numb, int n) { int deg = 0; for (int i = 0; i < n; i++) { if (adj_matrix[numb][i] == 1) { deg++; } } return deg; }

其中,n为顶点数,MAX_V为顶点最大数目。函数返回值为顶点numb的度数。

写出一代码求出邻接矩阵表示的无向图中序号为numb的顶点的度数。

原文地址: https://www.cveoy.top/t/topic/g0s4 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录