import Foundation class QuickSortSolution { func sort(_ n: [Int]) -> [Int] { var s = n quickSort(&s, 0, n.count - 1) return s } func quickSort(_ n: inout [Int],_ left: Int,_ right: Int) { if left < right { let mid = ...
import Foundation class MergeSortSolution { func sort(_ n: [Int]) -> [Int] { var s = n sortArray(&s, 0, n.count - 1) return s } func sortArray(_ n: inout [Int],_ left: Int,_ right: Int){ if left < right { let mid = (...
import Foundation class InsertSortSolution { func sort(_ n: [Int]) -> [Int] { var nums = n for i in 0..<nums.count { var j = i while j-1>=0 && nums[j] < nums[j-1] { let temp = nums[j] nums[j...
import Foundation class HeapSortSolution { func sort(_ n: [Int]) -> [Int] { var s = n //1.初始化堆 var i = n.count/2 - 1 while i >= 0 { heapAdjust(&s, i, n.count - 1) i -= 1 } var j = n.c...