Three way partition the data into smaller, equal and greater lists, in relationship to the pivot :param data: The data to be sorted (a list) :param pivot: The value to partition the data on :return: Three list: smaller, equal and greater
(data, pivot)
| 5 | https://en.wikipedia.org/wiki/Quickselect |
| 6 | """ |
| 7 | def _partition(data, pivot): |
| 8 | """ |
| 9 | Three way partition the data into smaller, equal and greater lists, |
| 10 | in relationship to the pivot |
| 11 | :param data: The data to be sorted (a list) |
| 12 | :param pivot: The value to partition the data on |
| 13 | :return: Three list: smaller, equal and greater |
| 14 | """ |
| 15 | less, equal, greater = [], [], [] |
| 16 | for element in data: |
| 17 | if element.address < pivot.address: |
| 18 | less.append(element) |
| 19 | elif element.address > pivot.address: |
| 20 | greater.append(element) |
| 21 | else: |
| 22 | equal.append(element) |
| 23 | return less, equal, greater |
| 24 | |
| 25 | def quickSelect(list, k): |
| 26 | #k = len(list) // 2 when trying to find the median (index that value would be when list is sorted) |