From f985113fd6103f4e1c257f04b00edae4a55dc187 Mon Sep 17 00:00:00 2001 From: Yash Mistry <76916876+yashms25@users.noreply.github.com> Date: Wed, 6 Oct 2021 12:01:23 +0530 Subject: [PATCH 1/2] Create Quicksort.py Implementation of quick sort in python --- .../Python/Sorting/Quicksort.py | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 DataStructure_and_Algorithms/Python/Sorting/Quicksort.py 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)) + From 30d47b46586cf283044b600fa98a04b7bea442a7 Mon Sep 17 00:00:00 2001 From: Yash Mistry <76916876+yashms25@users.noreply.github.com> Date: Wed, 6 Oct 2021 12:04:57 +0530 Subject: [PATCH 2/2] Create Selectionsort.py --- .../Python/Sorting/Selectionsort.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 DataStructure_and_Algorithms/Python/Sorting/Selectionsort.py 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))