<s> __author__ = """<STR_LIT>""" <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> from os import getcwd <EOL> from os import sys <EOL> sys . path . append ( getcwd ( ) ) <EOL> from MOAL . helpers . display import Section <EOL> from MOAL . helpers . generic import swap_item <EOL> from MOAL . helpers . trials import run_sorting_trials <EOL> from pprint import pprint as ppr <EOL> def quick_sort ( items , low = None , high = None ) : <EOL> def partition ( items , low , high ) : <EOL> pivot_index = ( low + high ) / <NUM_LIT:2> <EOL> pivot_value = items [ pivot_index ] <EOL> items = swap_item ( items , pivot_index , high ) <EOL> store_index = low <EOL> for k in range ( low , high ) : <EOL> if items [ k ] < pivot_value : <EOL> items = swap_item ( items , k , store_index ) <EOL> store_index += <NUM_LIT:1> <EOL> items = swap_item ( items , store_index , high ) <EOL> return store_index <EOL> num_items = len ( items ) <EOL> if len ( items ) < <NUM_LIT:2> : <EOL> return items <EOL> if low is None : <EOL> low = <NUM_LIT:0> <EOL> if high is None : <EOL> high = num_items - <NUM_LIT:1> <EOL> if low < high : <EOL> partitioned = partition ( items , low , high ) <EOL> quick_sort ( items , low = low , high = partitioned - <NUM_LIT:1> ) <EOL> quick_sort ( items , low = partitioned + <NUM_LIT:1> , high = high ) <EOL> return items <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> with Section ( '<STR_LIT>' ) : <EOL> ppr ( run_sorting_trials ( quick_sort , magnitudes = [ <NUM_LIT:10> , <NUM_LIT:100> , <NUM_LIT:1000> ] ) ) </s>
