数据结构-图 学习笔记
图结构:
一种非线性数据结构。每个数据元素之间可以任意关联,就构成一个图结构。也正是这种任意关联性,导致了图结构中数据关系
的
复杂性。
研究图结构的一个专门理论工具便是图论。
一个典型的图结构包括以下两个部分:
顶点:图中的数据元素。
边:图中连接这些顶点的线。
所有的顶点构成一个顶点集合,所有的边构成边集合,一个完整的图结构就是由顶点集合和边集合组成。图结构在数学上一般记为以下形式:
G=(V,E) 或者 G=(V(G),E(G)) V(G):表示图结构中所有顶点的集合; E(G):图结构中所有边的集合;
Java代码实现:
public class MyGraph {
/**顶点*/
private static class Vertex {
}
/**边*/
private static class Edge {
int srcVert; //起始边
int destVert; //目的边
int distance; //距离
Edge(int sv,int dv,int dt){
this.srcVert = sv;
this.destVert = dv;
this.distance = dt;
}
}
}
注: