From b492e6441708fc82e85d44cc87353178afd85342 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Mon, 13 Jan 2020 19:56:06 +0100 Subject: [PATCH] Create pull_request_template.md (#1684) * Create pull_request_template.md * fixup! Format Python code with psf/black push * Update pull_request_template.md * updating DIRECTORY.md * Update pull_request_template.md * Update pull_request_template.md * Update pull_request_template.md * Update pull_request_template.md * Update pull_request_template.md * Typos and formatting Co-authored-by: John Law --- .github/pull_request_template.md | 19 +++++++++++++++++++ DIRECTORY.md | 5 ++++- sorts/recursive_insertion_sort.py | 15 +++++++++------ 3 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 .github/pull_request_template.md diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 000000000..2f130896e --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,19 @@ +### **Describe your change:** + + + +* [ ] Add an algorithm? +* [ ] Fix a bug or typo in an existing algorithm? +* [ ] Documentation change? + +### **Checklist:** +* [ ] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md). +* [ ] This pull request is all my own work -- I have not plagiarized. +* [ ] I know that pull requests will not be merged if they fail the automated tests. +* [ ] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. +* [ ] All new Python files are placed inside an existing directory. +* [ ] All filenames are in all lowercase characters with no spaces or dashes. +* [ ] All functions and variable names follow Python naming conventions. +* [ ] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html). +* [ ] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing. +* [ ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation. diff --git a/DIRECTORY.md b/DIRECTORY.md index 1116e8539..75dea10d3 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -122,12 +122,12 @@ * [Linked Stack](https://github.com/TheAlgorithms/Python/blob/master/data_structures/stacks/linked_stack.py) * [Next Greater Element](https://github.com/TheAlgorithms/Python/blob/master/data_structures/stacks/next_greater_element.py) * [Postfix Evaluation](https://github.com/TheAlgorithms/Python/blob/master/data_structures/stacks/postfix_evaluation.py) + * [Prefix Evaluation](https://github.com/TheAlgorithms/Python/blob/master/data_structures/stacks/prefix_evaluation.py) * [Stack](https://github.com/TheAlgorithms/Python/blob/master/data_structures/stacks/stack.py) * [Stack Using Dll](https://github.com/TheAlgorithms/Python/blob/master/data_structures/stacks/stack_using_dll.py) * [Stock Span Problem](https://github.com/TheAlgorithms/Python/blob/master/data_structures/stacks/stock_span_problem.py) * Trie * [Trie](https://github.com/TheAlgorithms/Python/blob/master/data_structures/trie/trie.py) - * [Prefix Evaluation](https://github.com/TheAlgorithms/Python/blob/master/data_structures/prefix_evaluation.py) ## Digital Image Processing * [Change Contrast](https://github.com/TheAlgorithms/Python/blob/master/digital_image_processing/change_contrast.py) @@ -152,6 +152,8 @@ * [Inversions](https://github.com/TheAlgorithms/Python/blob/master/divide_and_conquer/inversions.py) * [Max Subarray Sum](https://github.com/TheAlgorithms/Python/blob/master/divide_and_conquer/max_subarray_sum.py) * [Mergesort](https://github.com/TheAlgorithms/Python/blob/master/divide_and_conquer/mergesort.py) + * [Power](https://github.com/TheAlgorithms/Python/blob/master/divide_and_conquer/power.py) + * [Strassen Matrix Multiplication](https://github.com/TheAlgorithms/Python/blob/master/divide_and_conquer/strassen_matrix_multiplication.py) ## Dynamic Programming * [Abbreviation](https://github.com/TheAlgorithms/Python/blob/master/dynamic_programming/abbreviation.py) @@ -537,6 +539,7 @@ * [Random Pivot Quick Sort](https://github.com/TheAlgorithms/Python/blob/master/sorts/random_pivot_quick_sort.py) * [Recursive-Quick-Sort](https://github.com/TheAlgorithms/Python/blob/master/sorts/recursive-quick-sort.py) * [Recursive Bubble Sort](https://github.com/TheAlgorithms/Python/blob/master/sorts/recursive_bubble_sort.py) + * [Recursive Insertion Sort](https://github.com/TheAlgorithms/Python/blob/master/sorts/recursive_insertion_sort.py) * [Selection Sort](https://github.com/TheAlgorithms/Python/blob/master/sorts/selection_sort.py) * [Shell Sort](https://github.com/TheAlgorithms/Python/blob/master/sorts/shell_sort.py) * [Stooge Sort](https://github.com/TheAlgorithms/Python/blob/master/sorts/stooge_sort.py) diff --git a/sorts/recursive_insertion_sort.py b/sorts/recursive_insertion_sort.py index a8bd2b911..39a903dd1 100644 --- a/sorts/recursive_insertion_sort.py +++ b/sorts/recursive_insertion_sort.py @@ -4,6 +4,7 @@ A recursive implementation of the insertion sort algorithm from typing import List + def rec_insertion_sort(collection: List, n: int): """ Given a collection of numbers and its length, sorts the collections @@ -27,13 +28,13 @@ def rec_insertion_sort(collection: List, n: int): >>> print(col) [1] """ - #Checks if the entire collection has been sorted + # Checks if the entire collection has been sorted if len(collection) <= 1 or n <= 1: return + insert_next(collection, n - 1) + rec_insertion_sort(collection, n - 1) - insert_next(collection, n-1) - rec_insertion_sort(collection, n-1) def insert_next(collection: List, index: int): """ @@ -54,17 +55,19 @@ def insert_next(collection: List, index: int): >>> print(col) [] """ - #Checks order between adjacent elements + # Checks order between adjacent elements if index >= len(collection) or collection[index - 1] <= collection[index]: return - #Swaps adjacent elements since they are not in ascending order + # Swaps adjacent elements since they are not in ascending order collection[index - 1], collection[index] = ( - collection[index], collection[index - 1] + collection[index], + collection[index - 1], ) insert_next(collection, index + 1) + if __name__ == "__main__": numbers = input("Enter integers seperated by spaces: ") numbers = [int(num) for num in numbers.split()]