def quick_sort(S): if len(S) <= 1: return S pivot = S[-1] # pick last element as pivot left = [x for x in S[:-1] if x <= pivot] right = [x for x in S[:-1] if x > pivot] return quick_sort(left) + [pivot] + quick_sort(right) # Main Program while True: n = int(input("Enter number of elements (greater than zero): ")) if n > 0: S = [int(input(f"Enter element {i+1}: ")) for i in range(n)] print("Elements before sorting:", S) S = quick_sort(S) print("Elements after sorting :", S) else: print("Invalid input!") c = int(input("Press 1 to continue, 0 to exit: ")) if c != 1: print("Program Terminated") break