@@ -90,6 +90,15 @@ public extension Array where Element: Comparable {
9090 }
9191 return items
9292 }
93+
94+ /// Bubble Sort, automatically compared by `l < r`
95+ ///
96+ /// - Returns: Sorted Array
97+ public func bubbleSortAutomatically( ) -> [ Element ] {
98+ return self . bubbleSort ( by: { ( l, r) -> Bool in
99+ return l < r
100+ } )
101+ }
93102
94103 // MAKR: - 插入排序
95104 /// Insertion Sort
@@ -113,6 +122,15 @@ public extension Array where Element: Comparable {
113122 }
114123 return items
115124 }
125+
126+ /// Insertion Sort, automatically compared by `l < r`
127+ ///
128+ /// - Returns: Sorted Array
129+ public func insertionSortAutomatically( ) -> [ Element ] {
130+ return self . insertionSort ( by: { ( l, r) -> Bool in
131+ return l < r
132+ } )
133+ }
116134
117135 // MARK: - 归并排序
118136 /// Merge Sort
@@ -151,6 +169,15 @@ public extension Array where Element: Comparable {
151169 return internal_merge ( left: left, right: right, by: compare)
152170 }
153171 }
172+
173+ /// Merge Sort, automatically compared by `l < r`
174+ ///
175+ /// - Returns: Sorted Array
176+ public func mergeSortAutomatically( ) -> [ Element ] {
177+ return self . mergeSort ( by: { ( l, r) -> Bool in
178+ return l < r
179+ } )
180+ }
154181
155182 // MARK: - 快速排序
156183 /// Quick Sort
@@ -191,4 +218,13 @@ public extension Array where Element: Comparable {
191218 internal_quickSort ( & items, left: 0 , right: items. count- 1 , by: compare)
192219 return items
193220 }
221+
222+ /// Quick Sort, automatically compared by `l < r`
223+ ///
224+ /// - Returns: Sorted Array
225+ public func quickSortAutomatically( ) -> [ Element ] {
226+ return self . quickSort ( by: { ( l, r) -> Bool in
227+ return l < r
228+ } )
229+ }
194230}
0 commit comments