Skip to content

Commit f144470

Browse files
authored
Merge pull request kodecocodes#845 from gmotzespina/master
Solved - Bubble Sort Readme Code Issue kodecocodes#838
2 parents 98c0d55 + d01fb8d commit f144470

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

Bubble Sort/README.markdown

+6-6
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ This is the same for the forth and fifth passes.
5757
```swift
5858
for i in 0..<array.count {
5959
for j in 1..<array.count {
60-
if array[j] < array[i] {
61-
let tmp = array[i]
62-
array[i] = array[j]
60+
if array[j] < array[j-1] {
61+
let tmp = array[j-1]
62+
array[j-1] = array[j]
6363
array[j] = tmp
6464
}
6565
}
@@ -73,9 +73,9 @@ The bubble sort algorithm can be easily optimized by observing that the `n-th` p
7373
```swift
7474
for i in 0..<array.count {
7575
for j in 1..<array.count - i {
76-
if array[j] < array[i] {
77-
let tmp = array[i]
78-
array[i] = array[j]
76+
if array[j] < array[j-1] {
77+
let tmp = array[j-1]
78+
array[j-1] = array[j]
7979
array[j] = tmp
8080
}
8181
}

0 commit comments

Comments
 (0)