algorithm - Quicksort with Python -
i totally new python , trying implement quicksort in it. please me complete code?
i not know how concatenate 3 arrays , printing them.
def sort(array=[12,4,5,6,7,3,1,15]): less = [] equal = [] greater = [] if len(array) > 1: pivot = array[0] x in array: if x < pivot: less.append(x) if x == pivot: equal.append(x) if x > pivot: greater.append(x) sort(less) sort(pivot) sort(greater)
def sort(array=[12,4,5,6,7,3,1,15]): less = [] equal = [] greater = [] if len(array) > 1: pivot = array[0] x in array: if x < pivot: less.append(x) if x == pivot: equal.append(x) if x > pivot: greater.append(x) # don't forget return something! return sort(less)+equal+sort(greater) # use + operator join lists # note want equal ^^^^^ not pivot else: # need hande part @ end of recursion - when have 1 element in array, return array. return array
Comments
Post a Comment