Download 7S.py from Madhan-Alagarsamy/Python: direct link, hf CLI and curl.
- Browser
- Download file 735 Bytes
-
https://huggingface.co/datasets/Madhan-Alagarsamy/Python/resolve/main/7S.py
- Command line
-
hf download hf://datasets/Madhan-Alagarsamy/Python/7S.py
-
curl -L -o 7S.py https://huggingface.co/datasets/Madhan-Alagarsamy/Python/resolve/main/7S.py
735 Bytes
| 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 | |