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 075fa49

Browse files
Update bubble_sort.py
Existing optimized code is not giving correct answer.
1 parent bfaf2b9 commit 075fa49

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

‎bubble_sort.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ def bubbleSortOptimized(arr):
2424

2525
for j in range(0, len(arr)-i-1):
2626

27-
if arr[i] > arr[j]:
28-
arr[i], arr[j] = arr[j], arr[i]
27+
if arr[j] > arr[j+1]:
28+
arr[j], arr[j+1] = arr[j+1], arr[j]
2929
swapped = True
3030

3131
# if no elements are swapped, break the loop

0 commit comments

Comments
(0)

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