Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Foundation
- func bubbleSort(_ list: [Int]) -> [Int]{
- var array = list
- var swapped = true
- while swapped{
- swapped = false
- for i in 0..<array.count-1{
- if array[i] > array[i+1]{
- swap(&array[i], &array[i+1])
- swapped = true
- }
- }
- }
- return array
- }
- let list = [ 10, -1, 3, 9, 2, 27, 8, 5, 1, 3, 0, 26 ]
- let result = bubbleSort(list)
- print(result)
Add Comment
Please, Sign In to add comment