Pārlūkot izejas kodu

add classes about graph.

171870002 5 gadi atpakaļ
vecāks
revīzija
a0bd7e916d

+ 77 - 0
src/main/java/com/example/data_structure/domain/UDUWGraph.java

@@ -0,0 +1,77 @@
+package com.example.data_structure.domain;
+
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+
+@Component
+public class UDUWGraph {
+    private int nodeNum;
+    private int edgeNum;
+    private ArrayList<ArrayList<Integer>> content;
+
+
+    public UDUWGraph(ArrayList<ArrayList<Integer>> content) {
+        this.content = content;
+        this.nodeNum=content.size();
+        int edgeNum=0;
+        for(int i=1;i<nodeNum;i++){
+            for(int j=0;j<i;j++){
+                if(content.get(i).get(j)!=0){
+                    edgeNum++;
+                };
+            }
+        }
+        this.edgeNum=edgeNum;
+    }
+
+    //getter
+    public UDUWGraph() {
+    }
+
+    public int getNodeNum() {
+        return nodeNum;
+    }
+
+    public int getEdgeNum() {
+        return edgeNum;
+    }
+
+    public ArrayList<ArrayList<Integer>> getContent() {
+        return content;
+    }
+
+    //setter
+    public void setNodeNum(int nodeNum) {
+        this.nodeNum = nodeNum;
+    }
+
+    public void setEdgeNum(int edgeNum) {
+        this.edgeNum = edgeNum;
+    }
+
+    public void setContent(ArrayList<ArrayList<Integer>> content) {
+        this.content = content;
+    }
+
+    public String toMatrixString(){
+        String re="nodeNum: "+nodeNum+"\nedgeNum: "+edgeNum+"\n";
+        for(int i=0;i<nodeNum;i++){
+            for(int j=0;j<nodeNum;j++){
+                re=re+content.get(i).get(j)+" ";
+            }
+            re=re+"\n";
+        }
+        return re;
+
+    }
+
+    @Override
+    public String toString() {
+        return "UDUWGraph{" +
+                "nodeNum=" + nodeNum +
+                ", edgeNum=" + edgeNum +
+                ", content=" + content +
+                '}';
+    }
+}

+ 76 - 0
src/main/java/com/example/data_structure/domain/UDWGraph.java

@@ -0,0 +1,76 @@
+package com.example.data_structure.domain;
+
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+
+@Component
+public class UDWGraph {
+    private int nodeNum;
+    private int edgeNum;
+    private ArrayList<ArrayList<Integer>> content;
+
+
+    public UDWGraph(ArrayList<ArrayList<Integer>> content) {
+        this.content = content;
+        this.nodeNum=content.size();
+        int edgeNum=0;
+        for(int i=1;i<nodeNum;i++){
+            for(int j=0;j<i;j++){
+                if(content.get(i).get(j)!=0){
+                    edgeNum++;
+                };
+            }
+        }
+        this.edgeNum=edgeNum;
+    }
+
+    //getter
+    public UDWGraph() {
+    }
+
+    public int getNodeNum() {
+        return nodeNum;
+    }
+
+    public int getEdgeNum() {
+        return edgeNum;
+    }
+
+    public ArrayList<ArrayList<Integer>> getContent() {
+        return content;
+    }
+
+    //setter
+    public void setNodeNum(int nodeNum) {
+        this.nodeNum = nodeNum;
+    }
+
+    public void setEdgeNum(int edgeNum) {
+        this.edgeNum = edgeNum;
+    }
+
+    public void setContent(ArrayList<ArrayList<Integer>> content) {
+        this.content = content;
+    }
+
+    public String toMatrixString() {
+        String re = "nodeNum: " + nodeNum + "\nedgeNum: " + edgeNum + "\n";
+        for (int i = 0; i < nodeNum; i++) {
+            for (int j = 0; j < nodeNum; j++) {
+                re = re + content.get(i).get(j) + " ";
+            }
+            re = re + "\n";
+        }
+        return re;
+    }
+
+    @Override
+    public String toString() {
+        return "UDWGraph{" +
+                "nodeNum=" + nodeNum +
+                ", edgeNum=" + edgeNum +
+                ", content=" + content +
+                '}';
+    }
+}

+ 51 - 0
src/main/java/com/example/data_structure/vo/GraphSearchStep.java

@@ -0,0 +1,51 @@
+package com.example.data_structure.vo;
+
+public class GraphSearchStep {
+    private String type; //有两个值,一个是visit,一个是tryRoad
+    private int Start;
+    private int end;
+
+    public GraphSearchStep(String type, int start, int end) {
+        this.type = type;
+        Start = start;
+        this.end = end;
+    }
+
+    public GraphSearchStep() {
+    }
+
+    //getter
+    public String getType() {
+        return type;
+    }
+
+    public int getStart() {
+        return Start;
+    }
+
+    public int getEnd() {
+        return end;
+    }
+
+    //setter
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public void setStart(int start) {
+        Start = start;
+    }
+
+    public void setEnd(int end) {
+        this.end = end;
+    }
+
+    @Override
+    public String toString() {
+        return "GraphSearchStep{" +
+                "type='" + type + '\'' +
+                ", Start=" + Start +
+                ", end=" + end +
+                '}';
+    }
+}

+ 44 - 0
src/main/java/com/example/data_structure/vo/GraphSearchVO.java

@@ -0,0 +1,44 @@
+package com.example.data_structure.vo;
+
+import com.example.data_structure.domain.UDUWGraph;
+
+import java.util.ArrayList;
+
+public class GraphSearchVO {
+    private UDUWGraph graph;
+    private ArrayList<GraphSearchStep> content;
+
+    public GraphSearchVO(UDUWGraph graph, ArrayList<GraphSearchStep> content) {
+        this.graph = graph;
+        this.content = content;
+    }
+
+    public GraphSearchVO() {
+    }
+
+    //getter
+    public UDUWGraph getGraph() {
+        return graph;
+    }
+
+    public ArrayList<GraphSearchStep> getContent() {
+        return content;
+    }
+
+    //setter
+    public void setGraph(UDUWGraph graph) {
+        this.graph = graph;
+    }
+
+    public void setContent(ArrayList<GraphSearchStep> content) {
+        this.content = content;
+    }
+
+    @Override
+    public String toString() {
+        return "GraphSearchVO{" +
+                "graph=" + graph +
+                ", content=" + content +
+                '}';
+    }
+}