// 深搜 private void dfs(int v) { visited[v] = true; System.out.print(v+" "); for (int i = 0; ique = new LinkedList (); que.offer(v); while (!que.isEmpty()) { v = que.poll(); System.out.print(v+" "); visited[v] = true; //将被访问节点的分支节点(邻接点)加入到队列中 for (int i = 0; i
public class ALGraph implements IGraph{ //图的邻接表类的描述 private GraphKind kind; private int vexNum,arcNum; private VNode[] vexs; public void createGraph() { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); System.out.println("请输入图的类型"); GraphKind kind =GraphKind.valueOf(sc.next()); switch(kind) { case UDG: createUDG(); break; case DG: createDG(); break; case UDN: createUDN(); break; case DN: createDN(); break; } } private void createDN() { // TODO Auto-generated method stub //创建有向网 Scanner sc=new Scanner(System.in); System.out.println("下面要创建带权的有向图(有向网)。请分别输入图的顶点数、图的边数"); vexNum=sc.nextInt(); arcNum=sc.nextInt(); vexs=new VNode[vexNum]; System.out.println("请分别输入图的各顶点"); for(int v=0;v
//图的邻接表表示中的顶点节点类public class VNode { private Object data;// 顶点信息 private ArcNode firstArc; //指向第一条依附于该顶点的弧}//图的邻接表表示中 边结点 类public class ArcNode { private int adjVex;//该弧所指向的顶点位置 private int value;//边或弧的权值 private ArcNode nextArc;//指向下一条弧}