| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- package com.example.data_structure.domain;
- import java.util.ArrayList;
- public class Graph {
- private boolean isDirected; //是否有向
- private boolean isWeighted; //是否带权
- private int nodeNum; //结点数
- private int edgeNum;//边数
- private ArrayList<String> nodeList; //各结点名称
- private ArrayList<ArrayList<Boolean>> graph; //图中结点和边的连接关系
- private ArrayList<ArrayList<Double>>weight;//各边权重
- /**
- * 没有权重的图的构造方法
- * @param isDirected
- * @param nodeNum
- * @param edgeNum
- * @param nodeList
- * @param graph
- */
- public Graph(boolean isDirected, int nodeNum, int edgeNum, ArrayList<String> nodeList, ArrayList<ArrayList<Boolean>> graph) {
- this.isDirected = isDirected;
- this.isWeighted=false;
- this.nodeNum = nodeNum;
- this.edgeNum = edgeNum;
- this.nodeList = nodeList;
- this.graph = graph;
- this.weight=null;
- }
- /**
- * 带权图构造方法
- * @param isDirected
- * @param isWeighted
- * @param nodeNum
- * @param edgeNum
- * @param nodeList
- * @param graph
- * @param weight
- */
- public Graph(boolean isDirected, boolean isWeighted, int nodeNum, int edgeNum, ArrayList<String> nodeList, ArrayList<ArrayList<Boolean>> graph, ArrayList<ArrayList<Double>> weight) {
- this.isDirected = isDirected;
- this.isWeighted = isWeighted;
- this.nodeNum = nodeNum;
- this.edgeNum = edgeNum;
- this.nodeList = nodeList;
- this.graph = graph;
- this.weight = weight;
- }
- /**
- * 获取计算最小生成树过程中每一步的结果,返回一个结果列表
- * @return
- */
- public ArrayList<Graph> getMinimalSpanningTree(){
- return null;
- }
- /**
- * 获取广度优先遍历的结点遍历顺序
- * @return
- */
- public ArrayList<String> getBreadthFirstTraversal(){
- return null;
- }
- /**
- * 获取深度优先遍历的结点遍历顺序
- * @return
- */
- public ArrayList<String> getDepthFirstTraversal(){
- return null;
- }
- /*getter*/
- public boolean isDirected() {
- return isDirected;
- }
- public boolean isWeighted() {
- return isWeighted;
- }
- public int getNodeNum() {
- return nodeNum;
- }
- public int getEdgeNum() {
- return edgeNum;
- }
- public ArrayList<String> getNodeList() {
- return nodeList;
- }
- public ArrayList<ArrayList<Boolean>> getGraph() {
- return graph;
- }
- public ArrayList<ArrayList<Double>> getWeight() {
- return weight;
- }
- /*setter*/
- public void setDirected(boolean directed) {
- isDirected = directed;
- }
- public void setWeighted(boolean weighted) {
- isWeighted = weighted;
- }
- public void setNodeNum(int nodeNum) {
- this.nodeNum = nodeNum;
- }
- public void setEdgeNum(int edgeNum) {
- this.edgeNum = edgeNum;
- }
- public void setNodeList(ArrayList<String> nodeList) {
- this.nodeList = nodeList;
- }
- public void setGraph(ArrayList<ArrayList<Boolean>> graph) {
- this.graph = graph;
- }
- public void setWeight(ArrayList<ArrayList<Double>> weight) {
- this.weight = weight;
- }
- }
|