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 4b7c6de

Browse files
author
Muh. Angga Muttaqien
committed
add selection sort
1 parent a69a305 commit 4b7c6de

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

‎sorting/selection-sort.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
def selection_sort(collection):
3+
4+
length = len(collection)
5+
for i in range(length):
6+
least = i
7+
8+
for k in range(i + 1, length):
9+
if collection[k] < collection[least]:
10+
least = k
11+
12+
collection[least], collection[i] = (
13+
collection[i], collection[least]
14+
)
15+
16+
return collection
17+
18+
def main():
19+
print("=== Selection Sort (Algorithm) - A sorting algorithm that has thime complexity, making it inefficient on large lists, and generally performs worse than the other similar sort")
20+
numbers = raw_input("Enter numbers separated by a comma: ")
21+
unsorted = [int(item) for item in numbers.split(',')]
22+
print(selection_sort(unsorted))
23+
24+
if __name__=='__main__':
25+
main()

0 commit comments

Comments
(0)

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