171870002 5 лет назад
Родитель
Сommit
f5984c5178

+ 3201 - 41
data-structure接口返回值说明文档.md

@@ -1,6 +1,6 @@
 ## data-structure部分接口返回值说明文档
 
-## 1.冒泡排序
+## 1.冒泡排序(交换排序的一种)
 
 ### (1)符号说明
 
@@ -596,99 +596,3259 @@ RESPONSE:
 
 ### (3)postman实例测试
 
+{
+
+  "content": {
+
+​    "initial": {
+
+​      "type": "beforeCompare",
+
+​      "content": [
+
+​        {
+
+​          "value": 4,
+
+​          "color": "blue"
+
+​        },
+
+​        {
+
+​          "value": 3,
+
+​          "color": "blue"
+
+​        },
+
+​        {
+
+​          "value": 2,
+
+​          "color": "blue"
+
+​        },
+
+​        {
+
+​          "value": 1,
+
+​          "color": "blue"
+
+​        },
+
+​        {
+
+​          "value": 0,
+
+​          "color": "blue"
+
+​        }
+
+​      ]
+
+​    },
+
+​    "onSortingStates": [
+
+​      {
+
+​        "type": "onExtreme",
+
+​        "content": [
+
+​          {
+
+​            "value": 4,
+
+​            "color": "red"
+
+​          },
+
+​          {
+
+​            "value": 3,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 2,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 1,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 0,
+
+​            "color": "blue"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "onCompare",
+
+​        "content": [
+
+​          {
+
+​            "value": 4,
+
+​            "color": "red"
+
+​          },
+
+​          {
+
+​            "value": 3,
+
+​            "color": "green"
+
+​          },
+
+​          {
+
+​            "value": 2,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 1,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 0,
+
+​            "color": "blue"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "onExtreme",
+
+​        "content": [
+
+​          {
+
+​            "value": 4,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 3,
+
+​            "color": "red"
+
+​          },
+
+​          {
+
+​            "value": 2,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 1,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 0,
+
+​            "color": "blue"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "onCompare",
+
+​        "content": [
+
+​          {
+
+​            "value": 4,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 3,
+
+​            "color": "red"
+
+​          },
+
+​          {
+
+​            "value": 2,
+
+​            "color": "green"
+
+​          },
+
+​          {
+
+​            "value": 1,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 0,
+
+​            "color": "blue"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "onExtreme",
+
+​        "content": [
+
+​          {
+
+​            "value": 4,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 3,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 2,
+
+​            "color": "red"
+
+​          },
+
+​          {
+
+​            "value": 1,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 0,
+
+​            "color": "blue"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "onCompare",
+
+​        "content": [
+
+​          {
+
+​            "value": 4,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 3,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 2,
+
+​            "color": "red"
+
+​          },
+
+​          {
+
+​            "value": 1,
+
+​            "color": "green"
+
+​          },
+
+​          {
+
+​            "value": 0,
+
+​            "color": "blue"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "onExtreme",
+
+​        "content": [
+
+​          {
+
+​            "value": 4,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 3,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 2,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 1,
+
+​            "color": "red"
+
+​          },
+
+​          {
+
+​            "value": 0,
+
+​            "color": "blue"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "onCompare",
+
+​        "content": [
+
+​          {
+
+​            "value": 4,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 3,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 2,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 1,
+
+​            "color": "red"
+
+​          },
+
+​          {
+
+​            "value": 0,
+
+​            "color": "green"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "onExtreme",
+
+​        "content": [
+
+​          {
+
+​            "value": 4,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 3,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 2,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 1,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 0,
+
+​            "color": "red"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "beforeExchange",
+
+​        "content": [
+
+​          {
+
+​            "value": 4,
+
+​            "color": "red"
+
+​          },
+
+​          {
+
+​            "value": 3,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 2,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 1,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 0,
+
+​            "color": "red"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "afterExchange",
+
+​        "content": [
+
+​          {
+
+​            "value": 0,
+
+​            "color": "red"
+
+​          },
+
+​          {
+
+​            "value": 3,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 2,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 1,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 4,
+
+​            "color": "red"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "beforeCompare",
+
+​        "content": [
+
+​          {
+
+​            "value": 0,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 3,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 2,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 1,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 4,
+
+​            "color": "blue"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "onExtreme",
+
+​        "content": [
+
+​          {
+
+​            "value": 0,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 3,
+
+​            "color": "red"
+
+​          },
+
+​          {
+
+​            "value": 2,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 1,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 4,
+
+​            "color": "blue"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "onCompare",
+
+​        "content": [
+
+​          {
+
+​            "value": 0,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 3,
+
+​            "color": "red"
+
+​          },
+
+​          {
+
+​            "value": 2,
+
+​            "color": "green"
+
+​          },
+
+​          {
+
+​            "value": 1,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 4,
+
+​            "color": "blue"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "onExtreme",
+
+​        "content": [
+
+​          {
+
+​            "value": 0,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 3,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 2,
+
+​            "color": "red"
+
+​          },
+
+​          {
+
+​            "value": 1,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 4,
+
+​            "color": "blue"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "onCompare",
+
+​        "content": [
+
+​          {
+
+​            "value": 0,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 3,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 2,
+
+​            "color": "red"
+
+​          },
+
+​          {
+
+​            "value": 1,
+
+​            "color": "green"
+
+​          },
+
+​          {
+
+​            "value": 4,
+
+​            "color": "blue"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "onExtreme",
+
+​        "content": [
+
+​          {
+
+​            "value": 0,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 3,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 2,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 1,
+
+​            "color": "red"
+
+​          },
+
+​          {
+
+​            "value": 4,
+
+​            "color": "blue"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "onCompare",
+
+​        "content": [
+
+​          {
+
+​            "value": 0,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 3,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 2,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 1,
+
+​            "color": "red"
+
+​          },
+
+​          {
+
+​            "value": 4,
+
+​            "color": "green"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "beforeExchange",
+
+​        "content": [
+
+​          {
+
+​            "value": 0,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 3,
+
+​            "color": "red"
+
+​          },
+
+​          {
+
+​            "value": 2,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 1,
+
+​            "color": "red"
+
+​          },
+
+​          {
+
+​            "value": 4,
+
+​            "color": "blue"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "afterExchange",
+
+​        "content": [
+
+​          {
+
+​            "value": 0,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 1,
+
+​            "color": "red"
+
+​          },
+
+​          {
+
+​            "value": 2,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 3,
+
+​            "color": "red"
+
+​          },
+
+​          {
+
+​            "value": 4,
+
+​            "color": "blue"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "beforeCompare",
+
+​        "content": [
+
+​          {
+
+​            "value": 0,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 1,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 2,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 3,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 4,
+
+​            "color": "blue"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "onExtreme",
+
+​        "content": [
+
+​          {
+
+​            "value": 0,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 1,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 2,
+
+​            "color": "red"
+
+​          },
+
+​          {
+
+​            "value": 3,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 4,
+
+​            "color": "blue"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "onCompare",
+
+​        "content": [
+
+​          {
+
+​            "value": 0,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 1,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 2,
+
+​            "color": "red"
+
+​          },
+
+​          {
+
+​            "value": 3,
+
+​            "color": "green"
+
+​          },
+
+​          {
+
+​            "value": 4,
+
+​            "color": "blue"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "onCompare",
+
+​        "content": [
+
+​          {
+
+​            "value": 0,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 1,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 2,
+
+​            "color": "red"
+
+​          },
+
+​          {
+
+​            "value": 3,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 4,
+
+​            "color": "green"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "beforeCompare",
+
+​        "content": [
+
+​          {
+
+​            "value": 0,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 1,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 2,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 3,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 4,
+
+​            "color": "blue"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "onExtreme",
+
+​        "content": [
+
+​          {
+
+​            "value": 0,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 1,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 2,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 3,
+
+​            "color": "red"
+
+​          },
+
+​          {
+
+​            "value": 4,
+
+​            "color": "blue"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "onCompare",
+
+​        "content": [
+
+​          {
+
+​            "value": 0,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 1,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 2,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 3,
+
+​            "color": "red"
+
+​          },
+
+​          {
+
+​            "value": 4,
+
+​            "color": "green"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "beforeCompare",
+
+​        "content": [
+
+​          {
+
+​            "value": 0,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 1,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 2,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 3,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 4,
+
+​            "color": "blue"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "allSorted",
+
+​        "content": [
+
+​          {
+
+​            "value": 0,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 1,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 2,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 3,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 4,
+
+​            "color": "blue"
+
+​          }
+
+​        ]
+
+​      }
+
+​    ]
+
+  },
+
+  "message": **null**,
+
+  "success": **true**
+
+}
+
+## 4.插入排序
+
+### (1)符号说明
+
+1.颜色和意义
+
+blue: 未被选中,还未排好序
+
+green: 在比较当中或在移动当中(在移动当中显示移动后的位置)
+
+red: 当前需要插入的值
+
+orange: 已排好序
+
+white: 空白bar (空白bar的color为white, value为0)
+
+2.状态和意义
+
+onSelect: 已选中下一个待插入目标,待插入目标已出列,但还未开始比较
+
+onCompare: 正在比较
+
+onExchange: 比较后发现逆序,与空白bar交换位置
+
+onInsertion: 比较和交换后发现此时空白bar就是应该把当前值插入的地方,显示插入后的结果(所有bar只有blue和orange两种颜色)
+
+allSorted: 所有的值都已排好序(全部为蓝色)
+
+### (2)接口返回值格式(只含response的content部分,实际的json还包含外面的response其他部分)
+
+{
+
+​		initial:
+
+​		[{value:  ,color:  },{value:  ,color:  },{value:  ,color:  },...]
+
+​		onSortingSates:
+
+​		[
+
+​			{
+
+​				type:
+
+​				insertionIndex: //空白bar所在的位置,从0开始。也是red bar的index。只有type为onSelect, onCompare, onExchange,时,
+
+​				content: [{value:  ,color:  },{value:  ,color:  },{value:  ,color:  },...]    //insertionIndex才有意义,onInsertion状态没有空白bar
+
+​			},																											//因此,onInsertion状态的insertionIndex为该值插入的下标。
+
+​			{
+
+​				type:
+
+​				insertionIndex:
+
+​				content: [{value:  ,color:  },{value:  ,color:  },{value:  ,color:  },...]
+
+​			},
+
+​			{
+
+​				type:
+
+​				insertionIndex:
+
+​				content: [{value:  ,color:  },{value:  ,color:  },{value:  ,color:  },...]
+
+​			},
+
+​					...
+
+​		]
+
+​	}
+
+### (3)postman实例测试
+
+{
+
+  "content": {
+
+​    "initial": {
+
+​      "type": "onInsertion",
+
+​      "insertionIndex": 0,
+
+​      "content": [
+
+​        {
+
+​          "value": 4,
+
+​          "color": "blue"
+
+​        },
+
+​        {
+
+​          "value": 3,
+
+​          "color": "blue"
+
+​        },
+
+​        {
+
+​          "value": 2,
+
+​          "color": "blue"
+
+​        },
+
+​        {
+
+​          "value": 1,
+
+​          "color": "blue"
+
+​        },
+
+​        {
+
+​          "value": 0,
+
+​          "color": "blue"
+
+​        }
+
+​      ]
+
+​    },
+
+​    "onSortingStates": [
+
+​      {
+
+​        "type": "onInsertion",
+
+​        "insertionIndex": 0,
+
+​        "content": [
+
+​          {
+
+​            "value": 4,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 3,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 2,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 1,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 0,
+
+​            "color": "blue"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "onSelect",
+
+​        "insertionIndex": 1,
+
+​        "content": [
+
+​          {
+
+​            "value": 4,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 3,
+
+​            "color": "white"
+
+​          },
+
+​          {
+
+​            "value": 2,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 1,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 0,
+
+​            "color": "blue"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "onCompare",
+
+​        "insertionIndex": 1,
+
+​        "content": [
+
+​          {
+
+​            "value": 4,
+
+​            "color": "green"
+
+​          },
+
+​          {
+
+​            "value": 3,
+
+​            "color": "white"
+
+​          },
+
+​          {
+
+​            "value": 2,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 1,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 0,
+
+​            "color": "blue"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "onExchange",
+
+​        "insertionIndex": 0,
+
+​        "content": [
+
+​          {
+
+​            "value": 3,
+
+​            "color": "white"
+
+​          },
+
+​          {
+
+​            "value": 4,
+
+​            "color": "green"
+
+​          },
+
+​          {
+
+​            "value": 2,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 1,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 0,
+
+​            "color": "blue"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "onInsertion",
+
+​        "insertionIndex": 0,
+
+​        "content": [
+
+​          {
+
+​            "value": 3,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 4,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 2,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 1,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 0,
+
+​            "color": "blue"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "onSelect",
+
+​        "insertionIndex": 2,
+
+​        "content": [
+
+​          {
+
+​            "value": 3,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 4,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 2,
+
+​            "color": "white"
+
+​          },
+
+​          {
+
+​            "value": 1,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 0,
+
+​            "color": "blue"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "onCompare",
+
+​        "insertionIndex": 2,
+
+​        "content": [
+
+​          {
+
+​            "value": 3,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 4,
+
+​            "color": "green"
+
+​          },
+
+​          {
+
+​            "value": 2,
+
+​            "color": "white"
+
+​          },
+
+​          {
+
+​            "value": 1,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 0,
+
+​            "color": "blue"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "onExchange",
+
+​        "insertionIndex": 1,
+
+​        "content": [
+
+​          {
+
+​            "value": 3,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 2,
+
+​            "color": "white"
+
+​          },
+
+​          {
+
+​            "value": 4,
+
+​            "color": "green"
+
+​          },
+
+​          {
+
+​            "value": 1,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 0,
+
+​            "color": "blue"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "onCompare",
+
+​        "insertionIndex": 1,
+
+​        "content": [
+
+​          {
+
+​            "value": 3,
+
+​            "color": "green"
+
+​          },
+
+​          {
+
+​            "value": 2,
+
+​            "color": "white"
+
+​          },
+
+​          {
+
+​            "value": 4,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 1,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 0,
+
+​            "color": "blue"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "onExchange",
+
+​        "insertionIndex": 0,
+
+​        "content": [
+
+​          {
+
+​            "value": 2,
+
+​            "color": "white"
+
+​          },
+
+​          {
+
+​            "value": 3,
+
+​            "color": "green"
+
+​          },
+
+​          {
+
+​            "value": 4,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 1,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 0,
+
+​            "color": "blue"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "onInsertion",
+
+​        "insertionIndex": 0,
+
+​        "content": [
+
+​          {
+
+​            "value": 2,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 3,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 4,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 1,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 0,
+
+​            "color": "blue"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "onSelect",
+
+​        "insertionIndex": 3,
+
+​        "content": [
+
+​          {
+
+​            "value": 2,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 3,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 4,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 1,
+
+​            "color": "white"
+
+​          },
+
+​          {
+
+​            "value": 0,
+
+​            "color": "blue"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "onCompare",
+
+​        "insertionIndex": 3,
+
+​        "content": [
+
+​          {
+
+​            "value": 2,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 3,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 4,
+
+​            "color": "green"
+
+​          },
+
+​          {
+
+​            "value": 1,
+
+​            "color": "white"
+
+​          },
+
+​          {
+
+​            "value": 0,
+
+​            "color": "blue"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "onExchange",
+
+​        "insertionIndex": 2,
+
+​        "content": [
+
+​          {
+
+​            "value": 2,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 3,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 1,
+
+​            "color": "white"
+
+​          },
+
+​          {
+
+​            "value": 4,
+
+​            "color": "green"
+
+​          },
+
+​          {
+
+​            "value": 0,
+
+​            "color": "blue"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "onCompare",
+
+​        "insertionIndex": 2,
+
+​        "content": [
+
+​          {
+
+​            "value": 2,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 3,
+
+​            "color": "green"
+
+​          },
+
+​          {
+
+​            "value": 1,
+
+​            "color": "white"
+
+​          },
+
+​          {
+
+​            "value": 4,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 0,
+
+​            "color": "blue"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "onExchange",
+
+​        "insertionIndex": 1,
+
+​        "content": [
+
+​          {
+
+​            "value": 2,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 1,
+
+​            "color": "white"
+
+​          },
+
+​          {
+
+​            "value": 3,
+
+​            "color": "green"
+
+​          },
+
+​          {
+
+​            "value": 4,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 0,
+
+​            "color": "blue"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "onCompare",
+
+​        "insertionIndex": 1,
+
+​        "content": [
+
+​          {
+
+​            "value": 2,
+
+​            "color": "green"
+
+​          },
+
+​          {
+
+​            "value": 1,
+
+​            "color": "white"
+
+​          },
+
+​          {
+
+​            "value": 3,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 4,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 0,
+
+​            "color": "blue"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "onExchange",
+
+​        "insertionIndex": 0,
+
+​        "content": [
+
+​          {
+
+​            "value": 1,
+
+​            "color": "white"
+
+​          },
+
+​          {
+
+​            "value": 2,
+
+​            "color": "green"
+
+​          },
+
+​          {
+
+​            "value": 3,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 4,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 0,
+
+​            "color": "blue"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "onInsertion",
+
+​        "insertionIndex": 0,
+
+​        "content": [
+
+​          {
+
+​            "value": 1,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 2,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 3,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 4,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 0,
+
+​            "color": "blue"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "onSelect",
+
+​        "insertionIndex": 4,
+
+​        "content": [
+
+​          {
+
+​            "value": 1,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 2,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 3,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 4,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 0,
+
+​            "color": "white"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "onCompare",
+
+​        "insertionIndex": 4,
+
+​        "content": [
+
+​          {
+
+​            "value": 1,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 2,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 3,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 4,
+
+​            "color": "green"
+
+​          },
+
+​          {
+
+​            "value": 0,
+
+​            "color": "white"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "onExchange",
+
+​        "insertionIndex": 3,
+
+​        "content": [
+
+​          {
+
+​            "value": 1,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 2,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 3,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 0,
+
+​            "color": "white"
+
+​          },
+
+​          {
+
+​            "value": 4,
+
+​            "color": "green"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "onCompare",
+
+​        "insertionIndex": 3,
+
+​        "content": [
+
+​          {
+
+​            "value": 1,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 2,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 3,
+
+​            "color": "green"
+
+​          },
+
+​          {
+
+​            "value": 0,
+
+​            "color": "white"
+
+​          },
+
+​          {
+
+​            "value": 4,
+
+​            "color": "orange"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "onExchange",
+
+​        "insertionIndex": 2,
+
+​        "content": [
+
+​          {
+
+​            "value": 1,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 2,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 0,
+
+​            "color": "white"
+
+​          },
+
+​          {
+
+​            "value": 3,
+
+​            "color": "green"
+
+​          },
+
+​          {
+
+​            "value": 4,
+
+​            "color": "orange"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "onCompare",
+
+​        "insertionIndex": 2,
+
+​        "content": [
+
+​          {
+
+​            "value": 1,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 2,
+
+​            "color": "green"
+
+​          },
+
+​          {
+
+​            "value": 0,
+
+​            "color": "white"
+
+​          },
+
+​          {
+
+​            "value": 3,
 
+​            "color": "orange"
 
-## 4.插入排序
+​          },
 
-### (1)符号说明
+​          {
 
-1.颜色和意义
+​            "value": 4,
 
-blue: 未被选中,还未排好序
+​            "color": "orange"
 
-green: 在比较当中或在移动当中(在移动当中显示移动后的位置)
+​          }
 
-red: 当前需要插入的值
+​        ]
 
-orange: 已排好序
+​      },
 
-white: 空白bar (空白bar的color为white, value为0)
+​      {
 
-2.状态和意义
+​        "type": "onExchange",
 
-onSelect: 已选中下一个待插入目标,待插入目标已出列,但还未开始比较
+​        "insertionIndex": 1,
 
-onCompare: 正在比较
+​        "content": [
 
-onExchange: 比较后发现逆序,与空白bar交换位置
+​          {
 
-onInsertion: 比较和交换后发现此时空白bar就是应该把当前值插入的地方,显示插入后的结果(所有bar只有blue和orange两种颜色)
+​            "value": 1,
 
-allSorted: 所有的值都已排好序(全部为蓝色)
+​            "color": "orange"
 
-### (2)接口返回值格式(只含response的content部分,实际的json还包含外面的response其他部分)
+​          },
 
-{
+{
 
-​		initial:
+​            "value": 0,
 
-​		[{value:  ,color:  },{value:  ,color:  },{value:  ,color:  },...]
+​            "color": "white"
 
-​		onSortingSates:
+​          },
 
-​		[
+​          {
 
-​			{
+​            "value": 2,
 
-​				type:
+​            "color": "green"
 
-​				insertionIndex: //空白bar所在的位置,从0开始。也是red bar的index。只有type为onSelect, onCompare, onExchange,时,
+​          },
 
-​				content: [{value:  ,color:  },{value:  ,color:  },{value:  ,color:  },...]    //insertionIndex才有意义,onInsertion状态没有空白bar
+​          {
 
-​			},																											//因此,onInsertion状态的insertionIndex为该值插入的下标。
+​            "value": 3,
 
-​			{
+​            "color": "orange"
 
-​				type:
+​          },
 
-​				insertionIndex:
+​          {
 
-​				content: [{value:  ,color:  },{value:  ,color:  },{value:  ,color:  },...]
+​            "value": 4,
 
-​			},
+​            "color": "orange"
 
-​			{
+​          }
 
-​				type:
+​        ]
 
-​				insertionIndex:
+​      },
 
-​				content: [{value:  ,color:  },{value:  ,color:  },{value:  ,color:  },...]
+​      {
 
-​			},
+​        "type": "onCompare",
 
-​					...
+​        "insertionIndex": 1,
 
-​		]
+​        "content": [
 
-​	}
+​          {
 
-### (3)postman实例测试
+​            "value": 1,
+
+​            "color": "green"
+
+​          },
+
+​          {
+
+​            "value": 0,
+
+​            "color": "white"
+
+​          },
+
+​          {
+
+​            "value": 2,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 3,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 4,
+
+​            "color": "orange"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "onExchange",
+
+​        "insertionIndex": 0,
+
+​        "content": [
+
+​          {
+
+​            "value": 0,
+
+​            "color": "white"
+
+​          },
+
+​          {
+
+​            "value": 1,
+
+​            "color": "green"
+
+​          },
+
+​          {
+
+​            "value": 2,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 3,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 4,
+
+​            "color": "orange"
+
+​          }
+
+​        ]
+
+​      },
+
+​      {
+
+​        "type": "onInsertion",
+
+​        "insertionIndex": 0,
+
+​        "content": [
+
+​          {
+
+​            "value": 0,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 1,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 2,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 3,
+
+​            "color": "orange"
+
+​          },
+
+​          {
+
+​            "value": 4,
+
+​            "color": "orange"
+
+​          }
+
+​        ]
 
+​      },
+
+​      {
+
+​        "type": "allSorted",
+
+​        "insertionIndex": 0,
+
+​        "content": [
+
+​          {
+
+​            "value": 0,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 1,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 2,
+
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 3,
 
+​            "color": "blue"
+
+​          },
+
+​          {
+
+​            "value": 4,
+
+​            "color": "blue"
+
+​          }
+
+​        ]
+
+​      }
+
+​    ]
 
-## 5.快速排序
+  },
+
+  "message": **null**,
+
+  "success": **true**
+
+}
+
+## 5.快速排序(交换排序的一种)
 
 ### (1)符号说明
 
 1.颜色和意义
 
+yello: 当前的pivot
 
+purple: 已比较并被标记为比pivot大的部分
+
+red: 当前与pivot比较的值
+
+green: 已比较并被标记为比pivot小的部分
+
+orange: 之前做过pivot,现在已经确定了最终的位置,即已排好序的部分
+
+blue: 未选中且未排好序的部分
 
 2.状态和意义
 
+beforeSelectPivot: 还未选择一个pivot,只有orange和blue两种颜色
+
+onSelectPivot: 选中一个pivot,还未开始比较和划分
+
+onCompare: 某一个值正在比较当中
+
+onExchange: 把比pivot小的值置换到storeIndex上去 (增序快排)
+
+onConfrim: 已筛选出比pivot大的和比pivot小的值,将pivot与最远的比pivot小的值交换,确定pivot的最终位置
 
+allSorted: 所有值都排好序了,所有的值都为蓝色
 
 ### (2)接口返回值格式(只含response的content部分,实际的json还包含外面的response其他部分)
 

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

@@ -5,6 +5,7 @@ import org.springframework.stereotype.Component;
 import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
+import java.util.Stack;
 
 @Service
 public class SortingService {
@@ -469,4 +470,30 @@ public class SortingService {
         return vo;
     }
 
+    //获取增序快速排序结果
+    public QuickSortVO getIncQuickSortResult(ArrayList<Integer> content){
+        int len=content.size();
+        Stack<ArrayList<Integer>> unsortedSegments = new Stack<ArrayList<Integer>>();
+        ArrayList<Integer> initialSeg= new ArrayList<Integer>();
+        initialSeg.add(0);
+        initialSeg.add(len-1);
+        unsortedSegments.push(initialSeg);
+        ArrayList<Integer> currentSeg=initialSeg;
+        while(!unsortedSegments.isEmpty()){
+            currentSeg=unsortedSegments.pop();
+
+        }
+        return null;
+    }
+
+    //获取降序快速排序结果
+    public QuickSortVO getDesQuickSortResult(ArrayList<Integer> content){
+        return null;
+    }
+
+    //获取快速排序结果
+    public QuickSortVO getQuickSortResult(ArrayList<Integer> content){
+        return null;
+    }
+
 }

+ 41 - 0
src/main/java/com/example/data_structure/vo/QuickSortVO.java

@@ -2,6 +2,47 @@ package com.example.data_structure.vo;
 
 import org.springframework.stereotype.Component;
 
+import java.util.ArrayList;
+
 @Component
 public class QuickSortVO {
+    private QuickStep initial;
+    private ArrayList<QuickStep> onSortingStates;
+
+    public QuickSortVO(QuickStep initial, ArrayList<QuickStep> onSortingStates) {
+        this.initial = initial;
+        this.onSortingStates = onSortingStates;
+    }
+
+    public QuickSortVO() {
+    }
+
+    //getter
+    public QuickStep getInitial() {
+        return initial;
+    }
+
+    public ArrayList<QuickStep> getOnSortingStates() {
+        return onSortingStates;
+    }
+
+
+    //setter
+    public void setInitial(QuickStep initial) {
+        this.initial = initial;
+    }
+
+    public void setOnSortingStates(ArrayList<QuickStep> onSortingStates) {
+        this.onSortingStates = onSortingStates;
+    }
+
+    //toString
+
+    @Override
+    public String toString() {
+        return "BubbleSortVO{" +
+                "initial=" + initial +
+                ", onSortingStates=" + onSortingStates +
+                '}';
+    }
 }

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

@@ -2,6 +2,57 @@ package com.example.data_structure.vo;
 
 import org.springframework.stereotype.Component;
 
+import java.util.ArrayList;
+
 @Component
 public class QuickStep {
+    private String type; //有六个值: beforeSelectPivot,onSelectPivot,onCompare,onExchange,onConfirm,allSorted
+    private ArrayList<Bar> content;
+
+    public QuickStep(String type, ArrayList<Bar> content) {
+        this.type = type;
+        this.content = content;
+    }
+
+    public QuickStep() {
+    }
+
+    //getter
+    public String getType() {
+        return type;
+    }
+
+    public ArrayList<Bar> getContent() {
+        return content;
+    }
+
+    //setter
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public void setContent(ArrayList<Bar> content) {
+        this.content = content;
+    }
+
+    //toString
+
+    @Override
+    public String toString() {
+        return "QuickStep{" +
+                "type='" + type + '\'' +
+                ", content=" + content +
+                '}';
+    }
+
+    //copy
+    public static ArrayList<Bar> copyContent(ArrayList<Bar> content){
+        ArrayList<Bar> copyContent=new ArrayList<Bar>();
+        for(int i=0;i<content.size();i++){
+            Bar bar=Bar.copyBar(content.get(i));
+            copyContent.add(bar);
+        }
+
+        return copyContent;
+    }
 }