Skip to content
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

Add Python bubble sort #303

Closed
wants to merge 2 commits into from
Closed
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
15 changes: 15 additions & 0 deletions bubble_sort/Python/bubble_sort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
def bubble_sort(seq):
changed = True
while changed:
changed = False
for i in range(len(seq) - 1):
if seq[i] > seq[i+1]:
seq[i], seq[i+1] = seq[i+1], seq[i]
changed = True
return seq

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code does not comply to PEP8.

Origin: PEP8Bear, Section: all.autopep8.

The issue can be fixed by applying the following patch:

--- a/tmp/tmpi7_g_6l6/bubble_sort/Python/bubble_sort.py
+++ b/tmp/tmpi7_g_6l6/bubble_sort/Python/bubble_sort.py
@@ -8,6 +8,7 @@
                 changed = True
     return seq
 
+
 if __name__ == "__main__":
     arr = [64, 34, 25, 12, 22, 11, 90]
     bubble_sort(arr)


if __name__ == "__main__":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E305 expected 2 blank lines after class or function definition, found 1

Origin: PycodestyleBear (E305), Section: all.autopep8.

arr = [64, 34, 25, 12, 22, 11, 90]
bubble_sort(arr)
print('Sorted array: ', arr)