小编mic*_*man的帖子

C:变量的值,无需重新赋值

我正在实施Kruskal的算法.

在以下代码中调用graph()后,节点的值会发生变化.我不太清楚为什么 - 如果有人能清楚这一点,我会非常感激.我没有从图中访问节点的值,并且正在访问的数组的节点和边都被分配到堆栈外部!

struct node {
  int parent, rank;
};
typedef struct node node;

struct edge {
  int fromvertex, tovertex;
  float weight;
};
typedef struct edge edge;

node* nodes;
edge* edges;

typedef enum {Unvisited, Visited} vertexstate;

int main (int argc, char const *argv[])
{
  void getcount(int*, int*);
  void graph(int, int);
  void makeset(int);
  int hasspantree(int, int, int);
  void kruskal(int, int);
  int printmcst(int);
  int nodecount, edgecount, i, totalcost=0;
  getcount(&nodecount, &edgecount);
  for (i = 1; i <= nodecount; i++)
    makeset(i);
  printf("%d \t …
Run Code Online (Sandbox Code Playgroud)

c graph-algorithm kruskals-algorithm

1
推荐指数
1
解决办法
276
查看次数

标签 统计

c ×1

graph-algorithm ×1

kruskals-algorithm ×1