Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Foundation
- func bubbleSort<T: Comparable>(_ array: [T]) -> [T] {
- var tempSort = array
- for _ in 1...tempSort.count {
- for i in 0..<tempSort.count - 1 {
- if tempSort[i] > tempSort[i + 1] {
- tempSort.swapAt(i, i + 1)
- }
- }
- }
- return tempSort
- }
- bubbleSort([7, 1, 8, 3, 6, 9, 2, 4, 5])
- bubbleSort(["Jen", "Oscar", "Todd", "Barry", "Clark", "Jamal"])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement