Download 7.py from Madhan-Alagarsamy/Python: direct link, hf CLI and curl.
- Browser
- Download file 1.31 kB
-
https://huggingface.co/datasets/Madhan-Alagarsamy/Python/resolve/main/7.py
- Command line
-
hf download hf://datasets/Madhan-Alagarsamy/Python/7.py
-
curl -L -o 7.py https://huggingface.co/datasets/Madhan-Alagarsamy/Python/resolve/main/7.py
1.31 kB
| def inplace_quick_sort(S, a, b): | |
| if a >= b: | |
| return | |
| pivot = S[b] | |
| left = a | |
| right = b - 1 | |
| while left <= right: | |
| while left <= right and S[left] < pivot: | |
| left += 1 | |
| while left <= right and S[right] > pivot: | |
| right -= 1 | |
| if left <= right: | |
| S[left], S[right] = S[right], S[left] | |
| left += 1 | |
| right -= 1 | |
| S[left], S[b] = S[b], S[left] | |
| inplace_quick_sort(S, a, left - 1) | |
| inplace_quick_sort(S, left + 1, b) | |
| while True: | |
| S = [] | |
| print("\tImplementation of In-place Quick-Sort algorithm using List") | |
| n = int(input("\nEnter number of elements (greater than Zero): ")) | |
| if n >= 1: | |
| print("Enter the elements one by one:") | |
| for i in range(n): | |
| S.append(int(input())) | |
| print("\nOutput") | |
| print("-------") | |
| print("\nElements before sorting:") | |
| print(S) | |
| inplace_quick_sort(S, 0, len(S) - 1) | |
| print("\nElements after sorting:") | |
| print(S) | |
| else: | |
| print("Invalid Input!") | |
| c = int(input("\nTo continue press 1 otherwise press 0... ")) | |
| if c != 1: | |
| print("Program Terminated") | |
| break | |