File tree Expand file tree Collapse file tree 1 file changed +12
-12
lines changed
Bubble Sort/MyPlayground.playground/Sources Expand file tree Collapse file tree 1 file changed +12
-12
lines changed Original file line number Diff line number Diff line change @@ -26,17 +26,17 @@ import Foundation
26
26
/// - Parameter elements: the array to be sorted
27
27
/// - Returns: an array with the same elements but in order
28
28
public func BubbleSort< T> ( _ elements: [ T ] ) -> [ T ] where T: Comparable {
29
- var array = elements
30
-
31
- for i in 0 ..< array. count {
32
- for j in 1 ..< array. count- i {
33
- if array [ j] < array [ j- 1 ] {
34
- let tmp = array [ j- 1 ]
35
- array [ j- 1 ] = array [ j]
36
- array [ j] = tmp
37
- }
38
- }
29
+ var array = elements
30
+
31
+ for i in 0 ..< array. count {
32
+ for j in 1 ..< array. count- i {
33
+ if array [ j] < array [ j- 1 ] {
34
+ let tmp = array [ j- 1 ]
35
+ array [ j- 1 ] = array [ j]
36
+ array [ j] = tmp
37
+ }
39
38
}
40
-
41
- return array
39
+ }
40
+
41
+ return array
42
42
}
You can’t perform that action at this time.
0 commit comments