diff options
Diffstat (limited to 'algorithms/impl')
-rw-r--r-- | algorithms/impl/bubble_sort.py | 8 | ||||
-rw-r--r-- | algorithms/impl/heapsort.py | 8 | ||||
-rw-r--r-- | algorithms/impl/insertion_sort.py | 8 | ||||
-rw-r--r-- | algorithms/impl/median.py | 8 | ||||
-rw-r--r-- | algorithms/impl/merge_sort.py | 8 | ||||
-rw-r--r-- | algorithms/impl/quicksort.py | 8 | ||||
-rw-r--r-- | algorithms/impl/selection_sort.py | 8 |
7 files changed, 35 insertions, 21 deletions
diff --git a/algorithms/impl/bubble_sort.py b/algorithms/impl/bubble_sort.py index e75ceab..95fb661 100644 --- a/algorithms/impl/bubble_sort.py +++ b/algorithms/impl/bubble_sort.py @@ -36,10 +36,12 @@ _ALGORITHMS = [ SortingAlgorithm('bubble_sort_optimized', 'Bubble sort (optimized)', bubble_sort_optimized), ] -def _parse_args(args=sys.argv): - return list(map(int, args[1:])) +def _parse_args(args=None): + if args is None: + args = sys.argv[1:] + return list(map(int, args)) -def main(args=sys.argv): +def main(args=None): xs = _parse_args(args) print(bubble_sort(list(xs))) print(bubble_sort_optimized(list(xs))) diff --git a/algorithms/impl/heapsort.py b/algorithms/impl/heapsort.py index 6615e14..bf9f464 100644 --- a/algorithms/impl/heapsort.py +++ b/algorithms/impl/heapsort.py @@ -58,10 +58,12 @@ _ALGORITHMS = [ SortingAlgorithm('heapsort', 'Heapsort', heapsort), ] -def _parse_args(args=sys.argv): - return list(map(int, args[1:])) +def _parse_args(args=None): + if args is None: + args = sys.argv[1:] + return list(map(int, args)) -def main(args=sys.argv): +def main(args=None): xs = _parse_args(args) print(heapsort(list(xs))) diff --git a/algorithms/impl/insertion_sort.py b/algorithms/impl/insertion_sort.py index d02b970..1abbf84 100644 --- a/algorithms/impl/insertion_sort.py +++ b/algorithms/impl/insertion_sort.py @@ -19,10 +19,12 @@ _ALGORITHMS = [ SortingAlgorithm('insertion_sort', 'Insertion sort', insertion_sort), ] -def _parse_args(args=sys.argv): - return list(map(int, args[1:])) +def _parse_args(args=None): + if args is None: + args = sys.argv[1:] + return list(map(int, args)) -def main(args=sys.argv): +def main(args=None): xs = _parse_args(args) print(insertion_sort(list(xs))) diff --git a/algorithms/impl/median.py b/algorithms/impl/median.py index d19dec4..b48e511 100644 --- a/algorithms/impl/median.py +++ b/algorithms/impl/median.py @@ -47,10 +47,12 @@ _ALGORITHMS = [ Algorithm('median_heaps', 'Median value (using heaps)', calc_median_heaps), ] -def _parse_args(args=sys.argv): - return list(map(int, args[1:])) +def _parse_args(args=None): + if args is None: + args = sys.argv[1:] + return list(map(int, args)) -def main(args=sys.argv): +def main(args=None): xs = _parse_args(args) print(calc_median_sorting(list(xs))) print(calc_median_heaps(list(xs))) diff --git a/algorithms/impl/merge_sort.py b/algorithms/impl/merge_sort.py index 3dd2bb9..2b96d21 100644 --- a/algorithms/impl/merge_sort.py +++ b/algorithms/impl/merge_sort.py @@ -33,10 +33,12 @@ _ALGORITHMS = [ SortingAlgorithm('merge_sort', 'Merge sort', merge_sort), ] -def _parse_args(args=sys.argv): - return list(map(int, args[1:])) +def _parse_args(args=None): + if args is None: + args = sys.argv[1:] + return list(map(int, args)) -def main(args=sys.argv): +def main(args=None): xs = _parse_args(args) print(merge_sort(list(xs))) diff --git a/algorithms/impl/quicksort.py b/algorithms/impl/quicksort.py index 3c4715a..1e835c4 100644 --- a/algorithms/impl/quicksort.py +++ b/algorithms/impl/quicksort.py @@ -69,10 +69,12 @@ _ALGORITHMS = [ SortingAlgorithm('quicksort_random', 'Quicksort (random element as pivot)', quicksort_random), ] -def _parse_args(args=sys.argv): - return list(map(int, args[1:])) +def _parse_args(args=None): + if args is None: + args = sys.argv[1:] + return list(map(int, args)) -def main(args=sys.argv): +def main(args=None): xs = _parse_args(args) print(quicksort_first(list(xs))) print(quicksort_second(list(xs))) diff --git a/algorithms/impl/selection_sort.py b/algorithms/impl/selection_sort.py index 0dbf4eb..ad4a420 100644 --- a/algorithms/impl/selection_sort.py +++ b/algorithms/impl/selection_sort.py @@ -21,10 +21,12 @@ _ALGORITHMS = [ SortingAlgorithm('selection_sort', 'Selection sort', selection_sort), ] -def _parse_args(args=sys.argv): - return list(map(int, args[1:])) +def _parse_args(args=None): + if args is None: + args = sys.argv[1:] + return list(map(int, args)) -def main(args=sys.argv): +def main(args=None): xs = _parse_args(args) print(selection_sort(list(xs))) |