瀏覽代碼

implement functions regarding bubble sort.

171870002 5 年之前
父節點
當前提交
b39b96d03f

+ 22 - 0
src/main/java/com/example/data_structure/controller/SortingController.java

@@ -1,7 +1,29 @@
 package com.example.data_structure.controller;
 
+import com.example.data_structure.common.Response;
+import com.example.data_structure.domain.Sorting;
+import com.example.data_structure.service.SortingService;
+import com.example.data_structure.vo.BubbleSortVO;
+import com.sun.corba.se.pept.transport.ResponseWaitingRoom;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+import java.util.ArrayList;
 
 @Controller
 public class SortingController {
+
+    @Autowired
+    SortingService sortingService;
+
+    @RequestMapping("/")
+    public Response getBubbleSortResult(String rule,ArrayList<Integer> content){
+        BubbleSortVO vo=sortingService.getBubbleSortResult(rule,content);
+        Response re=Response.buildSuccess(vo);
+        return re;
+    }
+
+    
+
 }

+ 13 - 0
src/main/java/com/example/data_structure/service/SortingService.java

@@ -173,4 +173,17 @@ public class SortingService {
         return bubbleVO;
     }
 
+
+    //获取冒泡排序结果
+    public BubbleSortVO getBubbleSortResult(String rule,ArrayList<Integer> content){
+        BubbleSortVO vo =new BubbleSortVO();
+        if(rule.equals("ascending")){
+            vo=getIncBubbleSortResult(content);
+        }else if(rule.equals("descending")){
+            vo=getDesBubbleSortResult(content);
+        }else{
+
+        }
+        return vo;
+    }
 }