hustcc / hustcc/JS-Sorting-Algorithm

快速排序的实现方式有优化空间

Đang mở
#64 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Java
Star
5.2k
Fork
1.1k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

快速排序的精髓在于“减少swap的次数”,目前的实现代码中,swap次数偏多,不够精简,在GIF动图的演示里也能看出问题。
正确的实现方式可以参考[wikipedia](https://zh.wikipedia.org/zh-sg/快速排序),以下是python实现方式的代码:
```python
def quickSort(arr, left=None, right=None):
left = 0 if not isinstance(left,(int, float)) else left
right = len(arr)-1 if not isinstance(right,(int, float)) else right
if left < right:
partitionIndex = partition(arr, left, right)
quickSort(arr, left, partitionIndex-1)
quickSort(arr, partitionIndex+1, right)
return arr

def partition(arr, left, right):
pivot = arr[right]
i, j= left, right - 1
while True:
while i<=j and arr[i]=pivot:
j-=1
if i

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.