Guest User

Untitled

a guest
Oct 21st, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. import Foundation
  2.  
  3. func bubbleSort(_ list: [Int]) -> [Int]{
  4. var array = list
  5. var swapped = true
  6. while swapped{
  7. swapped = false
  8. for i in 0..<array.count-1{
  9. if array[i] > array[i+1]{
  10. swap(&array[i], &array[i+1])
  11. swapped = true
  12. }
  13. }
  14. }
  15. return array
  16. }
  17.  
  18.  
  19. let list = [ 10, -1, 3, 9, 2, 27, 8, 5, 1, 3, 0, 26 ]
  20. let result = bubbleSort(list)
  21. print(result)
Add Comment
Please, Sign In to add comment