Sunday, March 19, 2017

A Quick Sort Code in Python

A Quick Sort Code in Python

In this post an efficient and short Quick Sort function is presented.

def QuickSort(arr):
    if len(arr) <= 1:
        return arr
    else:
        return QuickSort([x for x in arr[1:] if x < arr[0]]) + [arr[0]] + \
            QuickSort([x for x in arr[1:] if x >= arr[0]])


example = [15,4,2,6,17,4,11,19]

print(QuickSort(example))


Copyright ©2017, Software Developer, All rights reserved.
See Contents

No comments:

Post a Comment