Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. import Foundation
  2.  
  3. func bubbleSort<T: Comparable>(_ array: [T]) -> [T] {
  4. var tempSort = array
  5. for _ in 1...tempSort.count {
  6. for i in 0..<tempSort.count - 1 {
  7. if tempSort[i] > tempSort[i + 1] {
  8. tempSort.swapAt(i, i + 1)
  9. }
  10. }
  11. }
  12. return tempSort
  13. }
  14.  
  15. bubbleSort([7, 1, 8, 3, 6, 9, 2, 4, 5])
  16. bubbleSort(["Jen", "Oscar", "Todd", "Barry", "Clark", "Jamal"])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement