Michael-Jetson/ML_DL_CV_with_pytorch

Computer vision 里面那个quicksort可能是写者笔误了

Opened this issue · 0 comments

代码

def quicksort(arr):
    if len(arr) <= 1:
        return arr
    pivot = arr[len(arr) / 2]
    left = [x for x in arr if x < pivot]
    middle = [x for x in arr if x == pivot]
    right = [x for x in arr if x > pivot]
    return quicksort(left) + middle + quicksort(right)


print(quicksort([3, 6, 8, 10, 1, 2, 1]))

pivot应该用 //2, 如果是‘/’会导致数据类型变成浮点数而不是整形