Skip to content

Creating a python example of quicksort #205

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ Unlambder
Kjetil Johannessen
CDsigma
DominikRafacz
KerimovEmil
2 changes: 0 additions & 2 deletions chapters/euclidean_algorithm/code/python/euclidean_example.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
def euclid_mod(a, b):

a = abs(a)
b = abs(b)

Expand All @@ -9,7 +8,6 @@ def euclid_mod(a, b):
return a

def euclid_sub(a, b):

a = abs(a)
b = abs(b)

Expand Down
29 changes: 29 additions & 0 deletions chapters/sorting_searching/quicksort/code/python/quicksort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# submitted by KerimovEmil
import random


def quick_sort(array):
ls_lower = []
ls_upper = []
ls_pivot = []
if len(array) <= 1:
return array
else:
pivot = array[0] # pick any element from array
for i in array: # for each element in array, place in one of 3 lists
if i < pivot:
ls_lower.append(i)
elif i > pivot:
ls_upper.append(i)
else:
ls_pivot.append(i)
ls_lower = quick_sort(ls_lower)
ls_upper = quick_sort(ls_upper)
return ls_lower + ls_pivot + ls_upper


if __name__ == '__main__':
a = [random.randint(-100, 100) for _ in range(10)]
print("Before Sorting {}".format(a))
a = quick_sort(a)
print("After Sorting {}".format(a))
2 changes: 2 additions & 0 deletions chapters/sorting_searching/quicksort/quick_sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Quick Sort
# TODO make this file