|
|
@@ -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 +
|
|
|
+ '}';
|
|
|
+ }
|
|
|
+}
|