1.图的初始化:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 public interface IGraph{ 2 void createGraph(); 3 int getVexNum(); 4 int getArcNum(); 5 Object getVex(int v); 6 int locateVex(Object vex); 7 int firstAdjVex(int x); 8 int nextAdjVex(int v, int w); 9 } 10 public enum GraphKind{ 11 UDG, DG, UDN, DN; 12 } 13 public class MGraph implements IGraph{ 14 15 public final static int INFINITY = Integer.MAX_VALUE; 16 private GraphKind kind; 17 private int vexNum, arcNum; 18 private Object[] vexs; 19 private int[][] arcs; 20 21 public MGraph(GraphKind kind,... ){ 22 this.kind = kind; 23 this.vexNum = vexNum; 24 this.arcNum = arcNum; 25 this.vexs = vexs; 26 this.arcs = arcs; 27 } 28 public void createGraph(){ 29 Scanner sc = new Scanner(System.in); 30 System.out.printIn("请输入想创建的图的类型:") 31 //i = sc.next(); 32 GraphKind kind = GraphKind.valueOf(sc.next()); 33 switch (kind){ 34 case UDG: 35 createUDG(); 36 return; 37 case DG: 38 createDGDG(); 39 return; 40 case UDN: 41 createUDN(); 42 return; 43 case DN: 44 createDN; 45 return; 46 } 47 } 48 }