MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / sort

Function sort

sorts/intro_sort.py:137–163  ·  view source on GitHub ↗

:param collection: some mutable ordered collection with heterogeneous comparable items inside :return: the same collection ordered by ascending Examples: >>> sort([4, 2, 6, 8, 1, 7, 8, 22, 14, 56, 27, 79, 23, 45, 14, 12]) [1, 2, 4, 6, 7, 8, 8, 12, 14, 14, 22, 23, 27, 45, 56

(array: list)

Source from the content-addressed store, hash-verified

135
136
137def sort(array: list) -> list:
138 """
139 :param collection: some mutable ordered collection with heterogeneous
140 comparable items inside
141 :return: the same collection ordered by ascending
142
143 Examples:
144 >>> sort([4, 2, 6, 8, 1, 7, 8, 22, 14, 56, 27, 79, 23, 45, 14, 12])
145 [1, 2, 4, 6, 7, 8, 8, 12, 14, 14, 22, 23, 27, 45, 56, 79]
146 >>> sort([-1, -5, -3, -13, -44])
147 [-44, -13, -5, -3, -1]
148 >>> sort([])
149 []
150 >>> sort([5])
151 [5]
152 >>> sort([-3, 0, -7, 6, 23, -34])
153 [-34, -7, -3, 0, 6, 23]
154 >>> sort([1.7, 1.0, 3.3, 2.1, 0.3 ])
155 [0.3, 1.0, 1.7, 2.1, 3.3]
156 >>> sort(['d', 'a', 'b', 'e', 'c'])
157 ['a', 'b', 'c', 'd', 'e']
158 """
159 if len(array) == 0:
160 return array
161 max_depth = 2 * math.ceil(math.log2(len(array)))
162 size_threshold = 16
163 return intro_sort(array, 0, len(array), size_threshold, max_depth)
164
165
166def intro_sort(

Callers 2

intro_sort.pyFile · 0.85
median_filterFunction · 0.85

Calls 2

intro_sortFunction · 0.85
ceilMethod · 0.80

Tested by

no test coverage detected