Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 80304d7

Browse files
author
Muh. Angga Muttaqien
committed
add quick sort
1 parent 4b7c6de commit 80304d7

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

‎sorting/quick-sort.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
def quick_sort(collection):
3+
4+
length = len(collection)
5+
6+
if (length <= 1):
7+
return collection
8+
else:
9+
pivot = collection[0]
10+
greater = [item for item in collection[1:] if item > pivot]
11+
lesser = [item for item in collection[1:] if item <= pivot]
12+
13+
return quick_sort(lesser) + [pivot] + quick_sort(greater)
14+
15+
def main():
16+
print("=== Quick Sort (Algorithm) - An efficient sorting algorithm, serving as a systematic method for placing the elements of an array in order. It is still commonly used algorithm for sorting which is faster than its main competitors, merge-sort and heap-sort")
17+
numbers = raw_input("Enter numbers separated by a comma: ")
18+
unsorted = [int(item) for item in numbers.split(',')]
19+
print(quick_sort(unsorted))
20+
21+
if __name__=='__main__':
22+
main()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /