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 3e2bd2f

Browse files
author
Muh. Angga Muttaqien
committed
add bubble sort sorting algorithm
0 parents commit 3e2bd2f

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

‎sorting/bubble-sort.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
def bubble_sort(collection):
3+
4+
length = len(collection)
5+
for i in range(length-1, -1, -1):
6+
for j in range(i):
7+
if collection[j] > collection[j+1]:
8+
collection[j], collection[j+1] = collection[j+1], collection[j]
9+
10+
return collection
11+
12+
def main():
13+
print("=== Bubble Sort (Algorithm) - A simple algorithm that repeatedly steps through the list to be sorted. The algorithm is named for the way smaller or larger elements 'bubble' to the top of the list")
14+
numbers = raw_input("Enter numbers separated by a comma: ")
15+
unsorted = [int(item) for item in numbers.split(',')]
16+
print(bubble_sort(unsorted))
17+
18+
if __name__=='__main__':
19+
main()

0 commit comments

Comments
(0)

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