Consider the following Python code (Lomuto partition, last element as pivot).
def partition(a, lo, hi):
p, i = a[hi], lo - 1
for j in range(lo, hi):
if a[j] <= p:
i += 1
a[i], a[j] = a[j], a[i]
a[i + 1], a[hi] = a[hi], a[i + 1]
return i + 1
a = [5, 9, 2, 7, 3, 6]
partition(a, 0, 5)
print(a)
What does it print?
- A[5, 2, 3, 6, 9, 7]
- B[5, 2, 3, 6, 7, 9]
- C[2, 3, 5, 6, 7, 9]
- D[3, 5, 2, 6, 9, 7]