diff --git a/DataStructure_and_Algorithms/Python/Sorting/Quicksort.py b/DataStructure_and_Algorithms/Python/Sorting/Quicksort.py new file mode 100644 index 0000000..f02a15a --- /dev/null +++ b/DataStructure_and_Algorithms/Python/Sorting/Quicksort.py @@ -0,0 +1,34 @@ +from random import randint + +def quicksort(array): + + if len(array) < 2: + + return array + + low, same, high = [], [], [] + + pivot = array[randint(0, len(array) - 1)] + + for item in array: + + if item < pivot: + + low.append(item) + + elif item == pivot: + + same.append(item) + + elif item > pivot: + + high.append(item) + + return quicksort(low) + same + quicksort(high) + + + +arr = list(map(int,input().split())) + +print(quicksort(arr)) + diff --git a/DataStructure_and_Algorithms/Python/Sorting/Selectionsort.py b/DataStructure_and_Algorithms/Python/Sorting/Selectionsort.py new file mode 100644 index 0000000..7d76d62 --- /dev/null +++ b/DataStructure_and_Algorithms/Python/Sorting/Selectionsort.py @@ -0,0 +1,10 @@ +def sort(arr): + for i in range(len(arr)): + min_idx = i + for j in range(i+1, len(arr)): + if arr[min_idx] > arr[j]: + min_idx = j + arr[i], arr[min_idx] = arr[min_idx], arr[i] + return arr +arr = list(map(int,input("Enter Numbers: ").split())) +print(sort(arr))