DSL/quicksortEarlyAccess.py

40 lines
868 B
Python
Raw Normal View History

no = int(input("Enter number of students: "))
list2 = []
2023-10-16 19:07:36 +05:30
for i in range(0,no):
n = float(input("Enter % of student: "))
list2.append(n)
print(list2)
d = len(list2)
2023-10-16 19:07:36 +05:30
def partition(list3, low, high):
i = low - 1
pivot = list3[high]
for j in range(low, high):
if list3[j] < pivot:
i += 1
list3[i], list3[j] = list3[j], list3[i]
list3[i + 1], list3[high] = list3[high], list3[i + 1]
return i + 1
def quicksort(list1, low, high):
if low < high:
pi = partition(list1, low, high)
quicksort(list1, low, pi - 1)
quicksort(list1, pi + 1, high)
no = int(input("Enter number of students: "))
list2 = []
for i in range(0, no):
n = float(input("Enter % of student: "))
list2.append(n)
print("Unsorted list: ", list2)
quicksort(list2, 0, len(list2) - 1)
print("Sorted list: ", list2)