💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
## 图的Java数据结构 图的2要素:顶点集合和边集合 ~~~ public class Graph { // 顶点集 - 邻接表 public HashMap<String,Vertex> vertexs; // 边集 public Set<Edge> edges; public Graph() { this.vertexs = new HashMap<>(); this.edges = new HashSet<>(); } } ~~~ ~~~ // 顶点 class Vertex{ // 名称,值 public String value; // 入度 public Integer in; // 出度 public Integer out; // 相邻的顶点集合 public Set<Vertex> nexts; // 边集合 public Set<Edge> edges; public Vertex(String value) { this.value = value; this.in = 0; this.out = 0; this.nexts = new HashSet<>(); this.edges = new HashSet<>(); } } ~~~ ~~~ // 边 class Edge{ // 权重 public int weight; // 出发顶点 public Vertex from; // 到达顶点 public Vertex to; public Edge(int weight, Vertex from, Vertex to) { this.weight = weight; this.from = from; this.to = to; } } ~~~