public class BTraverser {
private static boolean[] visited;// 访问标志数组
// 对图G做广度优先遍历
public static void BFSTraverse(IGraph G) throws Exception {
visited = new boolean[()];// 访问标志数组
for (int v = 0; v < (); v++)
// 访问标志数组初始化
visited[v] = false;
for (int v = 0; v < (); v++)
if (!visited[v]) // v尚未访问
BFS(G, v);
}
private static void BFS(IGraph G, int v) throws Exception {
visited[v] = true;
((v).toString() + " ");
LinkQueue Q = new LinkQueue();// 辅助队列Q
(v);// v入队列
while (!()) {
int u = (Integer) ();// 队头元素出队列并赋值给u
for (int w = (u); w >= 0; w = (u, w))
if (!visited[w]) {// w为u的尚未访问的邻接顶点
visited[w] = true;
((w).toString() + " ");
(w);
}
}
}
public static void main(String[] args) throws Exception {
ALGraph G = ();
(G);
}
}