171870002 5 lat temu
rodzic
commit
7e972b5969

+ 296 - 0
data-structure接口返回值说明文档.md

@@ -3870,6 +3870,302 @@ allSorted: 所有值都排好序了,所有的值都为蓝色
 
 ### (2)接口返回值格式(只含response的content部分,实际的json还包含外面的response其他部分)
 
+1.URL:localhost:8080/graph/get-new-UDUWGraph
 
+{
+
+  "content": {
+
+​    "nodeNum": 7,
+
+​    "edgeNum": 11,
+
+​    "content": [
+
+​      [
+
+​        0,
+
+​        0,
+
+​        0,
+
+​        1,
+
+​        0,
+
+​        0,
+
+​        0
+
+​      ],
+
+​      [
+
+​        0,
+
+​        0,
+
+​        1,
+
+​        0,
+
+​        1,
+
+​        1,
+
+​        0
+
+​      ],
+
+​      [
+
+​        0,
+
+​        1,
+
+​        0,
+
+​        0,
+
+​        1,
+
+​        1,
+
+​        0
+
+​      ],
+
+​      [
+
+​        1,
+
+​        0,
+
+​        0,
+
+​        0,
+
+​        1,
+
+​        1,
+
+​        1
+
+​      ],
+
+​      [
+
+​        0,
+
+​        1,
+
+​        1,
+
+​        1,
+
+​        0,
+
+​        1,
+
+​        1
+
+​      ],
+
+​      [
+
+​        0,
+
+​        1,
+
+​        1,
+
+​        1,
+
+​        1,
+
+​        0,
+
+​        0
+
+​      ],
+
+​      [
+
+​        0,
+
+​        0,
+
+​        0,
+
+​        1,
+
+​        1,
+
+​        0,
+
+​        0
+
+​      ]
+
+​    ]
+
+  },
+
+  "message": **null**,
+
+  "success": **true**
+
+}
+
+
+
+2.URL:localhost:8080/graph/get-new-UDWGraph
+
+{
+
+  "content": {
+
+​    "nodeNum": 7,
+
+​    "edgeNum": 10,
+
+​    "content": [
+
+​      [
+
+​        0,
+
+​        9,
+
+​        0,
+
+​        6,
+
+​        0,
+
+​        0,
+
+​        0
+
+​      ],
+
+​      [
+
+​        9,
+
+​        0,
+
+​        7,
+
+​        0,
+
+​        9,
+
+​        0,
+
+​        0
+
+​      ],
+
+​      [
+
+​        0,
+
+​        7,
+
+​        0,
+
+​        7,
+
+​        1,
+
+​        2,
+
+​        2
+
+​      ],
+
+​      [
+
+​        6,
+
+​        0,
+
+​        7,
+
+​        0,
+
+​        4,
+
+​        0,
+
+​        0
+
+​      ],
+
+​      [
+
+​        0,
+
+​        9,
+
+​        1,
+
+​        4,
+
+​        0,
+
+​        6,
+
+​        0
+
+​      ],
+
+​      [
+
+​        0,
+
+​        0,
+
+​        2,
+
+​        0,
+
+​        6,
+
+​        0,
+
+​        0
+
+​      ],
+
+​      [
+
+​        0,
+
+​        0,
+
+​        2,
+
+​        0,
+
+​        0,
+
+​        0,
+
+​        0
+
+​      ]
+
+​    ]
+
+  },
+
+  "message": **null**,
+
+  "success": **true**
+
+}
 
 ### (3)postman实例测试

+ 12 - 0
src/main/java/com/example/data_structure/controller/GraphController.java

@@ -35,4 +35,16 @@ public class GraphController {
         PrimMinimumSpanningTree vo=graphService.getPrimMinimumSpanningTree(graph,startVertex);
         return Response.buildSuccess(vo);
     }
+
+    @GetMapping(value = "/graph/get-new-UDUWGraph")
+    public Response getNewUDUWGraph(){
+        UDUWGraph vo=graphService.getNewUDUWGraph();
+        return Response.buildSuccess(vo);
+    }
+
+    @GetMapping(value = "/graph/get-new-UDWGraph")
+    public Response getNewUDWGraph(){
+        UDWGraph vo=graphService.getNewUDWGraph();
+        return Response.buildSuccess(vo);
+    }
 }

+ 1 - 0
src/main/java/com/example/data_structure/controller/StackController.java

@@ -3,6 +3,7 @@ package com.example.data_structure.controller;
 
 import com.example.data_structure.common.Response;
 import com.example.data_structure.domain.Stack;
+import com.example.data_structure.domain.UDUWGraph;
 import com.example.data_structure.service.StackService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;

+ 7 - 7
src/main/java/com/example/data_structure/service/GraphService.java

@@ -14,7 +14,7 @@ import java.util.*;
 public class GraphService {
     private static final int NODE_NUM=7;
     //获取一个新的无向非带权图
-    public UDUWGraph getNewUDUDGraph(){
+    public UDUWGraph getNewUDUWGraph(){
         ArrayList<ArrayList<Integer>> content=new ArrayList<ArrayList<Integer>>();
         for(int i=0;i<NODE_NUM;i++){
             ArrayList<Integer> raw=new ArrayList<Integer>();
@@ -27,10 +27,10 @@ public class GraphService {
         int tokeTimes = Math.round(((float)Math.random())*10)+11;
         int edgeNum=0;
         for(int i=1;i<=tokeTimes;i++){
-            int left=Math.round(((float)Math.random())*7);
-            int right=Math.round(((float)Math.random())*7);
+            int left=Math.round(((float)Math.random())*6);
+            int right=Math.round(((float)Math.random())*6);
             while(left==right){
-                right=Math.round(((float)Math.random())*7);
+                right=Math.round(((float)Math.random())*6);
             }
             if(content.get(left).get(right)==1){
                 i--;
@@ -58,10 +58,10 @@ public class GraphService {
         int tokeTimes = Math.round(((float)Math.random())*10)+11;
         int edgeNum=0;
         for(int i=1;i<=tokeTimes;i++){
-            int left=Math.round(((float)Math.random())*7);
-            int right=Math.round(((float)Math.random())*7);
+            int left=Math.round(((float)Math.random())*6);
+            int right=Math.round(((float)Math.random())*6);
             while(left==right){
-                right=Math.round(((float)Math.random())*7);
+                right=Math.round(((float)Math.random())*6);
             }
             if(content.get(left).get(right)==1){
                 i--;

+ 14 - 0
src/test/java/com/example/data_structure/service/GraphServiceTest.java

@@ -66,4 +66,18 @@ public class GraphServiceTest {
         PrimMinimumSpanningTree vo=graphService.getPrimMinimumSpanningTree(graph,0);
         System.out.println(vo.toString());
     }
+
+    @Test
+    void newUDUWGraphTest(){
+        UDUWGraph vo=graphService.getNewUDUWGraph();
+        System.out.println(vo.toMatrixString());
+    }
+
+    @Test
+    void newUDWGraphTest(){
+        UDWGraph vo=graphService.getNewUDWGraph();
+        System.out.println(vo.toMatrixString());
+    }
+
+
 }