Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def partition(lst, low,high, pivot,col):
- lst[high],lst[pivot] = lst[pivot],lst[high]
- pivot = high
- i = low
- while i +1 <pivot:
- if lst[i][col] > lst[pivot][col]:
- lst[pivot], lst[pivot-1] = lst[pivot-1], lst[pivot]
- lst[i],lst[pivot] = lst[pivot],lst[i]
- pivot -= 1
- else:
- i +=1
- if lst[i][col] > lst[pivot][col]:
- lst[i],lst[pivot] = lst[pivot],lst[i]
- pivot -= 1
- return pivot
- def quick(lst,low,high,col,ascending):
- count[0] += 1
- if low >= high:
- return
- else:
- #print(low,high)
- pivot = random.randint(low,high)
- #print(pivot)
- part_point = partition(lst,low,high,pivot,col)
- print(part_point,high)
- quick(lst,low,part_point-1,col,ascending)
- quick(lst,part_point+1, high,col, ascending)
Add Comment
Please, Sign In to add comment