mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-02-20 00:02:04 +00:00
[mypy]Correction of all errors in the sorts directory (#4224)
* [mypy] Add/fix type annotations for recursive_insertion_sort(#4085) * [mypy] Add/fix type annotations for bucket_sort(#4085) * [mypy] Reworked code for cocktail_shaker_sort so that missing return statement error is resolved(#4085) * [mypy] Add/fix type annotations for patience_sort(#4085) * [mypy] Add/fix type annotations for radix_sort(#4085) Co-authored-by: goodm2 <4qjpngu8mem8cz>
This commit is contained in:
parent
02d9bc66c1
commit
a4726ca248
|
@ -27,6 +27,7 @@ If k = O(n), time complexity is O(n)
|
|||
|
||||
Source: https://en.wikipedia.org/wiki/Bucket_sort
|
||||
"""
|
||||
from typing import List
|
||||
|
||||
|
||||
def bucket_sort(my_list: list) -> list:
|
||||
|
@ -51,7 +52,7 @@ def bucket_sort(my_list: list) -> list:
|
|||
return []
|
||||
min_value, max_value = min(my_list), max(my_list)
|
||||
bucket_count = int(max_value - min_value) + 1
|
||||
buckets = [[] for _ in range(bucket_count)]
|
||||
buckets: List[list] = [[] for _ in range(bucket_count)]
|
||||
|
||||
for i in range(len(my_list)):
|
||||
buckets[(int(my_list[i] - min_value) // bucket_count)].append(my_list[i])
|
||||
|
|
|
@ -33,7 +33,8 @@ def cocktail_shaker_sort(unsorted: list) -> list:
|
|||
swapped = True
|
||||
|
||||
if not swapped:
|
||||
return unsorted
|
||||
break
|
||||
return unsorted
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
from bisect import bisect_left
|
||||
from functools import total_ordering
|
||||
from heapq import merge
|
||||
from typing import List
|
||||
|
||||
"""
|
||||
A pure Python implementation of the patience sort algorithm
|
||||
|
@ -43,7 +44,7 @@ def patience_sort(collection: list) -> list:
|
|||
>>> patience_sort([-3, -17, -48])
|
||||
[-48, -17, -3]
|
||||
"""
|
||||
stacks = []
|
||||
stacks: List[Stack] = []
|
||||
# sort into stacks
|
||||
for element in collection:
|
||||
new_stacks = Stack([element])
|
||||
|
|
|
@ -30,7 +30,7 @@ def radix_sort(list_of_ints: List[int]) -> List[int]:
|
|||
max_digit = max(list_of_ints)
|
||||
while placement <= max_digit:
|
||||
# declare and initialize empty buckets
|
||||
buckets = [list() for _ in range(RADIX)]
|
||||
buckets: List[list] = [list() for _ in range(RADIX)]
|
||||
# split list_of_ints between the buckets
|
||||
for i in list_of_ints:
|
||||
tmp = int((i / placement) % RADIX)
|
||||
|
|
|
@ -4,6 +4,8 @@ A recursive implementation of the insertion sort algorithm
|
|||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import List
|
||||
|
||||
|
||||
def rec_insertion_sort(collection: list, n: int):
|
||||
"""
|
||||
|
@ -70,6 +72,6 @@ def insert_next(collection: list, index: int):
|
|||
|
||||
if __name__ == "__main__":
|
||||
numbers = input("Enter integers separated by spaces: ")
|
||||
numbers = [int(num) for num in numbers.split()]
|
||||
rec_insertion_sort(numbers, len(numbers))
|
||||
print(numbers)
|
||||
number_list: List[int] = [int(num) for num in numbers.split()]
|
||||
rec_insertion_sort(number_list, len(number_list))
|
||||
print(number_list)
|
||||
|
|
Loading…
Reference in New Issue
Block a user