diff --git a/algorithm/sort.go b/algorithm/sort.go
index 84096a8..f2f8278 100644
--- a/algorithm/sort.go
+++ b/algorithm/sort.go
@@ -65,11 +65,15 @@ func ShellSort[T any](slice []T, comparator lancetconstraints.Comparator) {
}
// QuickSort quick sorting for slice, lowIndex is 0 and highIndex is len(slice)-1
-func QuickSort[T any](slice []T, lowIndex, highIndex int, comparator lancetconstraints.Comparator) {
+func QuickSort[T any](slice []T, comparator lancetconstraints.Comparator) {
+ quickSort(slice, 0, len(slice)-1, comparator)
+}
+
+func quickSort[T any](slice []T, lowIndex, highIndex int, comparator lancetconstraints.Comparator) {
if lowIndex < highIndex {
p := partition(slice, lowIndex, highIndex, comparator)
- QuickSort(slice, lowIndex, p-1, comparator)
- QuickSort(slice, p+1, highIndex, comparator)
+ quickSort(slice, lowIndex, p-1, comparator)
+ quickSort(slice, p+1, highIndex, comparator)
}
}
diff --git a/algorithm/sort_test.go b/algorithm/sort_test.go
index 281ed36..ee7e8c5 100644
--- a/algorithm/sort_test.go
+++ b/algorithm/sort_test.go
@@ -141,7 +141,7 @@ func TestQuickSort(t *testing.T) {
{Name: "e", Age: 28},
}
comparator := &peopleAgeComparator{}
- QuickSort(peoples, 0, len(peoples)-1, comparator)
+ QuickSort(peoples, comparator)
expected := "[{d 8} {b 10} {c 17} {a 20} {e 28}]"
actual := fmt.Sprintf("%v", peoples)
diff --git a/docs/algorithm.md b/docs/algorithm.md
index f1c7712..f96c09c 100644
--- a/docs/algorithm.md
+++ b/docs/algorithm.md
@@ -248,7 +248,7 @@ func main() {
Signature:
```go
-func QuickSort[T any](slice []T, lowIndex, highIndex int, comparator lancetconstraints.Comparator)
+func QuickSort[T any](slice []T comparator lancetconstraints.Comparator)
```
Example:
@@ -278,7 +278,7 @@ func main() {
intSlice := []int{2, 1, 5, 3, 6, 4}
comparator := &intComparator{}
- algorithm.QuickSort(intSlice, 0, len(intSlice)-1, comparator)
+ algorithm.QuickSort(intSlice, comparator)
fmt.Println(intSlice) //[]int{1, 2, 3, 4, 5, 6}
}
diff --git a/docs/algorithm_zh-CN.md b/docs/algorithm_zh-CN.md
index df6fe73..8c59161 100644
--- a/docs/algorithm_zh-CN.md
+++ b/docs/algorithm_zh-CN.md
@@ -249,7 +249,7 @@ func main() {
函数签名:
```go
-func QuickSort[T any](slice []T, lowIndex, highIndex int, comparator lancetconstraints.Comparator) []T
+func QuickSort[T any](slice []T, comparator lancetconstraints.Comparator) []T
```
Example:
@@ -279,7 +279,7 @@ func main() {
intSlice := []int{2, 1, 5, 3, 6, 4}
comparator := &intComparator{}
- algorithm.QuickSort(intSlice, 0, len(intSlice)-1, comparator)
+ algorithm.QuickSort(intSlice, comparator)
fmt.Println(intSlice) //[]int{1, 2, 3, 4, 5, 6}
}