标签:优先 enqueue rap 广度优先遍历 arc col while graph class
1.深度优先遍历
void dfs(Graph G,int i) { visted[i] = 1; for (int j = 0; i < G.vex; j++) { if (G.arcs[i][j]==1&&visted[j]!=1) { dfs(j); } } }
2.广度优先遍历
void bfs(Graph G,int i) { int e = 0; Queue q = createQueue(); visted[i] = 1; enQueue(q, i); while (isEmpty(q)) { e = deQueue(q); for (int j = 0; j < G.vexnum; j++) { if (G.arcs[e][j] == 1 && visted[j] != 1) { visted[j] = 1; enQueue(q, j); } } } }
好了,我们下回见,peace
标签:优先 enqueue rap 广度优先遍历 arc col while graph class
原文地址:https://www.cnblogs.com/gitpy123/p/13510310.html