diff --git a/codes/python/chapter_array_and_linkedlist/linked_list.py b/codes/python/chapter_array_and_linkedlist/linked_list.py index ae006db4..e51835d4 100644 --- a/codes/python/chapter_array_and_linkedlist/linked_list.py +++ b/codes/python/chapter_array_and_linkedlist/linked_list.py @@ -4,10 +4,11 @@ Created Time: 2022-11-25 Author: Krahets (krahets@163.com) """ -import sys, os.path as osp +import sys +from pathlib import Path -sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__)))) -from modules import * +sys.path.append(str(Path(__file__).parent.parent)) +from modules import ListNode, print_linked_list def insert(n0: ListNode, P: ListNode): diff --git a/codes/python/chapter_array_and_linkedlist/list.py b/codes/python/chapter_array_and_linkedlist/list.py index 468f2a08..b9ad6d35 100644 --- a/codes/python/chapter_array_and_linkedlist/list.py +++ b/codes/python/chapter_array_and_linkedlist/list.py @@ -43,7 +43,7 @@ if __name__ == "__main__": for i in range(len(nums)): tmp.append(nums[i]) print(f"\n通过索引遍历列表得到 tmp = {tmp}") - + tmp.clear() for num in nums: tmp.append(num) diff --git a/codes/python/chapter_backtracking/permutations_i.py b/codes/python/chapter_backtracking/permutations_i.py index d5c29d6c..6cca9101 100644 --- a/codes/python/chapter_backtracking/permutations_i.py +++ b/codes/python/chapter_backtracking/permutations_i.py @@ -4,11 +4,6 @@ Created Time: 2023-04-15 Author: Krahets (krahets@163.com) """ -import sys, os.path as osp - -sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__)))) -from modules import * - def backtrack( state: list[int], choices: list[int], selected: list[bool], res: list[list[int]] diff --git a/codes/python/chapter_backtracking/permutations_ii.py b/codes/python/chapter_backtracking/permutations_ii.py index fac0b37e..aaaffc68 100644 --- a/codes/python/chapter_backtracking/permutations_ii.py +++ b/codes/python/chapter_backtracking/permutations_ii.py @@ -4,11 +4,6 @@ Created Time: 2023-04-15 Author: Krahets (krahets@163.com) """ -import sys, os.path as osp - -sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__)))) -from modules import * - def backtrack( state: list[int], choices: list[int], selected: list[bool], res: list[list[int]] diff --git a/codes/python/chapter_backtracking/preorder_traversal_i_compact.py b/codes/python/chapter_backtracking/preorder_traversal_i_compact.py index f2d7177e..48a2f160 100644 --- a/codes/python/chapter_backtracking/preorder_traversal_i_compact.py +++ b/codes/python/chapter_backtracking/preorder_traversal_i_compact.py @@ -4,10 +4,11 @@ Created Time: 2023-04-15 Author: Krahets (krahets@163.com) """ -import sys, os.path as osp +import sys +from pathlib import Path -sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__)))) -from modules import * +sys.path.append(str(Path(__file__).parent.parent)) +from modules import TreeNode, print_tree, list_to_tree def pre_order(root: TreeNode): diff --git a/codes/python/chapter_backtracking/preorder_traversal_ii_compact.py b/codes/python/chapter_backtracking/preorder_traversal_ii_compact.py index 27bf00ba..9ef1ab6f 100644 --- a/codes/python/chapter_backtracking/preorder_traversal_ii_compact.py +++ b/codes/python/chapter_backtracking/preorder_traversal_ii_compact.py @@ -4,10 +4,11 @@ Created Time: 2023-04-15 Author: Krahets (krahets@163.com) """ -import sys, os.path as osp +import sys +from pathlib import Path -sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__)))) -from modules import * +sys.path.append(str(Path(__file__).parent.parent)) +from modules import TreeNode, print_tree, list_to_tree def pre_order(root: TreeNode): diff --git a/codes/python/chapter_backtracking/preorder_traversal_iii_compact.py b/codes/python/chapter_backtracking/preorder_traversal_iii_compact.py index dac756c7..22c55a8a 100644 --- a/codes/python/chapter_backtracking/preorder_traversal_iii_compact.py +++ b/codes/python/chapter_backtracking/preorder_traversal_iii_compact.py @@ -4,10 +4,11 @@ Created Time: 2023-04-15 Author: Krahets (krahets@163.com) """ -import sys, os.path as osp +import sys +from pathlib import Path -sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__)))) -from modules import * +sys.path.append(str(Path(__file__).parent.parent)) +from modules import TreeNode, print_tree, list_to_tree def pre_order(root: TreeNode): diff --git a/codes/python/chapter_backtracking/preorder_traversal_iii_template.py b/codes/python/chapter_backtracking/preorder_traversal_iii_template.py index ef5466a4..10a88c03 100644 --- a/codes/python/chapter_backtracking/preorder_traversal_iii_template.py +++ b/codes/python/chapter_backtracking/preorder_traversal_iii_template.py @@ -4,10 +4,11 @@ Created Time: 2023-04-15 Author: Krahets (krahets@163.com) """ -import sys, os.path as osp +import sys +from pathlib import Path -sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__)))) -from modules import * +sys.path.append(str(Path(__file__).parent.parent)) +from modules import TreeNode, print_tree, list_to_tree def is_solution(state: list[TreeNode]) -> bool: diff --git a/codes/python/chapter_computational_complexity/space_complexity.py b/codes/python/chapter_computational_complexity/space_complexity.py index 6b4cb90b..3080fd72 100644 --- a/codes/python/chapter_computational_complexity/space_complexity.py +++ b/codes/python/chapter_computational_complexity/space_complexity.py @@ -4,10 +4,11 @@ Created Time: 2022-11-25 Author: Krahets (krahets@163.com) """ -import sys, os.path as osp +import sys +from pathlib import Path -sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__)))) -from modules import * +sys.path.append(str(Path(__file__).parent.parent)) +from modules import ListNode, TreeNode, print_tree def function() -> int: diff --git a/codes/python/chapter_divide_and_conquer/build_tree.py b/codes/python/chapter_divide_and_conquer/build_tree.py index 970f1d4a..56f43702 100644 --- a/codes/python/chapter_divide_and_conquer/build_tree.py +++ b/codes/python/chapter_divide_and_conquer/build_tree.py @@ -4,10 +4,11 @@ Created Time: 2023-07-15 Author: Krahets (krahets@163.com) """ -import sys, os.path as osp +import sys +from pathlib import Path -sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__)))) -from modules import * +sys.path.append(str(Path(__file__).parent.parent)) +from modules import TreeNode, print_tree def dfs( diff --git a/codes/python/chapter_graph/graph_adjacency_list.py b/codes/python/chapter_graph/graph_adjacency_list.py index db8e534b..3d44998d 100644 --- a/codes/python/chapter_graph/graph_adjacency_list.py +++ b/codes/python/chapter_graph/graph_adjacency_list.py @@ -4,10 +4,11 @@ Created Time: 2023-02-23 Author: Krahets (krahets@163.com) """ -import sys, os.path as osp +import sys +from pathlib import Path -sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__)))) -from modules import * +sys.path.append(str(Path(__file__).parent.parent)) +from modules import Vertex, vals_to_vets class GraphAdjList: diff --git a/codes/python/chapter_graph/graph_adjacency_matrix.py b/codes/python/chapter_graph/graph_adjacency_matrix.py index a91ae21f..7c6f44fc 100644 --- a/codes/python/chapter_graph/graph_adjacency_matrix.py +++ b/codes/python/chapter_graph/graph_adjacency_matrix.py @@ -4,10 +4,11 @@ Created Time: 2023-02-23 Author: Krahets (krahets@163.com) """ -import sys, os.path as osp +import sys +from pathlib import Path -sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__)))) -from modules import * +sys.path.append(str(Path(__file__).parent.parent)) +from modules import Vertex, print_matrix class GraphAdjMat: diff --git a/codes/python/chapter_graph/graph_bfs.py b/codes/python/chapter_graph/graph_bfs.py index 24ad250c..a44a849b 100644 --- a/codes/python/chapter_graph/graph_bfs.py +++ b/codes/python/chapter_graph/graph_bfs.py @@ -4,10 +4,11 @@ Created Time: 2023-02-23 Author: Krahets (krahets@163.com) """ -import sys, os.path as osp +import sys +from pathlib import Path -sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__)))) -from modules import * +sys.path.append(str(Path(__file__).parent.parent)) +from modules import Vertex, vals_to_vets, vets_to_vals from collections import deque from graph_adjacency_list import GraphAdjList diff --git a/codes/python/chapter_graph/graph_dfs.py b/codes/python/chapter_graph/graph_dfs.py index 3acd74ac..2d8de8c3 100644 --- a/codes/python/chapter_graph/graph_dfs.py +++ b/codes/python/chapter_graph/graph_dfs.py @@ -4,10 +4,11 @@ Created Time: 2023-02-23 Author: Krahets (krahets@163.com) """ -import sys, os.path as osp +import sys +from pathlib import Path -sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__)))) -from modules import * +sys.path.append(str(Path(__file__).parent.parent)) +from modules import Vertex, vets_to_vals, vals_to_vets from graph_adjacency_list import GraphAdjList diff --git a/codes/python/chapter_hashing/built_in_hash.py b/codes/python/chapter_hashing/built_in_hash.py index bdb0b1e3..5ca5b4f8 100644 --- a/codes/python/chapter_hashing/built_in_hash.py +++ b/codes/python/chapter_hashing/built_in_hash.py @@ -4,10 +4,11 @@ Created Time: 2023-06-15 Author: Krahets (krahets@163.com) """ -import sys, os.path as osp +import sys +from pathlib import Path -sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__)))) -from modules import * +sys.path.append(str(Path(__file__).parent.parent)) +from modules import ListNode """Driver Code""" if __name__ == "__main__": diff --git a/codes/python/chapter_hashing/hash_map.py b/codes/python/chapter_hashing/hash_map.py index b9f52e3d..c1b1472c 100644 --- a/codes/python/chapter_hashing/hash_map.py +++ b/codes/python/chapter_hashing/hash_map.py @@ -4,10 +4,11 @@ Created Time: 2022-12-14 Author: msk397 (machangxinq@gmail.com) """ -import sys, os.path as osp +import sys +from pathlib import Path -sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__)))) -from modules import * +sys.path.append(str(Path(__file__).parent.parent)) +from modules import print_dict """Driver Code""" if __name__ == "__main__": diff --git a/codes/python/chapter_hashing/hash_map_chaining.py b/codes/python/chapter_hashing/hash_map_chaining.py index 1358650b..964de79e 100644 --- a/codes/python/chapter_hashing/hash_map_chaining.py +++ b/codes/python/chapter_hashing/hash_map_chaining.py @@ -4,9 +4,10 @@ Created Time: 2023-06-13 Author: Krahets (krahets@163.com) """ -import sys, os.path as osp +import sys +from pathlib import Path -sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__)))) +sys.path.append(str(Path(__file__).parent.parent)) from chapter_hashing.array_hash_map import Pair diff --git a/codes/python/chapter_hashing/hash_map_open_addressing.py b/codes/python/chapter_hashing/hash_map_open_addressing.py index 47585903..31d46e3d 100644 --- a/codes/python/chapter_hashing/hash_map_open_addressing.py +++ b/codes/python/chapter_hashing/hash_map_open_addressing.py @@ -4,9 +4,10 @@ Created Time: 2023-06-13 Author: Krahets (krahets@163.com) """ -import sys, os.path as osp +import sys +from pathlib import Path -sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__)))) +sys.path.append(str(Path(__file__).parent.parent)) from chapter_hashing.array_hash_map import Pair diff --git a/codes/python/chapter_heap/heap.py b/codes/python/chapter_heap/heap.py index 22a3362e..cf179d8a 100644 --- a/codes/python/chapter_heap/heap.py +++ b/codes/python/chapter_heap/heap.py @@ -4,10 +4,11 @@ Created Time: 2023-02-23 Author: Krahets (krahets@163.com) """ -import sys, os.path as osp +import sys +from pathlib import Path -sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__)))) -from modules import * +sys.path.append(str(Path(__file__).parent.parent)) +from modules import print_heap import heapq diff --git a/codes/python/chapter_heap/my_heap.py b/codes/python/chapter_heap/my_heap.py index 32f62b8d..2072a6cd 100644 --- a/codes/python/chapter_heap/my_heap.py +++ b/codes/python/chapter_heap/my_heap.py @@ -4,10 +4,11 @@ Created Time: 2023-02-23 Author: Krahets (krahets@163.com) """ -import sys, os.path as osp +import sys +from pathlib import Path -sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__)))) -from modules import * +sys.path.append(str(Path(__file__).parent.parent)) +from modules import print_heap class MaxHeap: diff --git a/codes/python/chapter_heap/top_k.py b/codes/python/chapter_heap/top_k.py index 5c6cae71..fea1c879 100644 --- a/codes/python/chapter_heap/top_k.py +++ b/codes/python/chapter_heap/top_k.py @@ -4,10 +4,11 @@ Created Time: 2023-06-10 Author: Krahets (krahets@163.com) """ -import sys, os.path as osp +import sys +from pathlib import Path -sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__)))) -from modules import * +sys.path.append(str(Path(__file__).parent.parent)) +from modules import print_heap import heapq diff --git a/codes/python/chapter_searching/binary_search_edge.py b/codes/python/chapter_searching/binary_search_edge.py index 55ae9b8a..5e4589a4 100644 --- a/codes/python/chapter_searching/binary_search_edge.py +++ b/codes/python/chapter_searching/binary_search_edge.py @@ -4,9 +4,10 @@ Created Time: 2023-08-04 Author: Krahets (krahets@163.com) """ -import sys, os.path as osp +import sys +from pathlib import Path -sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__)))) +sys.path.append(str(Path(__file__).parent.parent)) from binary_search_insertion import binary_search_insertion diff --git a/codes/python/chapter_searching/hashing_search.py b/codes/python/chapter_searching/hashing_search.py index cdcb9957..ae5c38b0 100644 --- a/codes/python/chapter_searching/hashing_search.py +++ b/codes/python/chapter_searching/hashing_search.py @@ -4,10 +4,11 @@ Created Time: 2022-11-26 Author: timi (xisunyy@163.com) """ -import sys, os.path as osp +import sys +from pathlib import Path -sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__)))) -from modules import * +sys.path.append(str(Path(__file__).parent.parent)) +from modules import ListNode, list_to_linked_list def hashing_search_array(hmap: dict[int, int], target: int) -> int: diff --git a/codes/python/chapter_searching/linear_search.py b/codes/python/chapter_searching/linear_search.py index 2ddb75a4..fb449e7b 100644 --- a/codes/python/chapter_searching/linear_search.py +++ b/codes/python/chapter_searching/linear_search.py @@ -4,10 +4,11 @@ Created Time: 2022-11-26 Author: timi (xisunyy@163.com) """ -import sys, os.path as osp +import sys +from pathlib import Path -sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__)))) -from modules import * +sys.path.append(str(Path(__file__).parent.parent)) +from modules import ListNode, list_to_linked_list def linear_search_array(nums: list[int], target: int) -> int: diff --git a/codes/python/chapter_stack_and_queue/linkedlist_queue.py b/codes/python/chapter_stack_and_queue/linkedlist_queue.py index 6f096133..42f227c1 100644 --- a/codes/python/chapter_stack_and_queue/linkedlist_queue.py +++ b/codes/python/chapter_stack_and_queue/linkedlist_queue.py @@ -4,10 +4,11 @@ Created Time: 2022-12-01 Author: Peng Chen (pengchzn@gmail.com) """ -import sys, os.path as osp +import sys +from pathlib import Path -sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__)))) -from modules import * +sys.path.append(str(Path(__file__).parent.parent)) +from modules import ListNode class LinkedListQueue: diff --git a/codes/python/chapter_stack_and_queue/linkedlist_stack.py b/codes/python/chapter_stack_and_queue/linkedlist_stack.py index ceb12c80..51ef7868 100644 --- a/codes/python/chapter_stack_and_queue/linkedlist_stack.py +++ b/codes/python/chapter_stack_and_queue/linkedlist_stack.py @@ -4,10 +4,11 @@ Created Time: 2022-11-29 Author: Peng Chen (pengchzn@gmail.com) """ -import sys, os.path as osp +import sys +from pathlib import Path -sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__)))) -from modules import * +sys.path.append(str(Path(__file__).parent.parent)) +from modules import ListNode class LinkedListStack: diff --git a/codes/python/chapter_tree/array_binary_tree.py b/codes/python/chapter_tree/array_binary_tree.py index 8b2a465e..0073a51a 100644 --- a/codes/python/chapter_tree/array_binary_tree.py +++ b/codes/python/chapter_tree/array_binary_tree.py @@ -4,10 +4,11 @@ Created Time: 2023-07-19 Author: Krahets (krahets@163.com) """ -import sys, os.path as osp +import sys +from pathlib import Path -sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__)))) -from modules import * +sys.path.append(str(Path(__file__).parent.parent)) +from modules import TreeNode, list_to_tree, print_tree class ArrayBinaryTree: diff --git a/codes/python/chapter_tree/avl_tree.py b/codes/python/chapter_tree/avl_tree.py index 51932c45..6f477c1f 100644 --- a/codes/python/chapter_tree/avl_tree.py +++ b/codes/python/chapter_tree/avl_tree.py @@ -4,10 +4,11 @@ Created Time: 2022-12-20 Author: a16su (lpluls001@gmail.com) """ -import sys, os.path as osp +import sys +from pathlib import Path -sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__)))) -from modules import * +sys.path.append(str(Path(__file__).parent.parent)) +from modules import TreeNode, print_tree class AVLTree: diff --git a/codes/python/chapter_tree/binary_search_tree.py b/codes/python/chapter_tree/binary_search_tree.py index 20ac6a82..d339bf8f 100644 --- a/codes/python/chapter_tree/binary_search_tree.py +++ b/codes/python/chapter_tree/binary_search_tree.py @@ -4,10 +4,11 @@ Created Time: 2022-12-20 Author: a16su (lpluls001@gmail.com) """ -import sys, os.path as osp +import sys +from pathlib import Path -sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__)))) -from modules import * +sys.path.append(str(Path(__file__).parent.parent)) +from modules import TreeNode, print_tree class BinarySearchTree: diff --git a/codes/python/chapter_tree/binary_tree.py b/codes/python/chapter_tree/binary_tree.py index 3539432d..a007e419 100644 --- a/codes/python/chapter_tree/binary_tree.py +++ b/codes/python/chapter_tree/binary_tree.py @@ -4,10 +4,11 @@ Created Time: 2022-12-20 Author: a16su (lpluls001@gmail.com) """ -import sys, os.path as osp +import sys +from pathlib import Path -sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__)))) -from modules import * +sys.path.append(str(Path(__file__).parent.parent)) +from modules import TreeNode, print_tree """Driver Code""" diff --git a/codes/python/chapter_tree/binary_tree_bfs.py b/codes/python/chapter_tree/binary_tree_bfs.py index e6c78c94..d75b1f68 100644 --- a/codes/python/chapter_tree/binary_tree_bfs.py +++ b/codes/python/chapter_tree/binary_tree_bfs.py @@ -4,10 +4,11 @@ Created Time: 2022-12-20 Author: a16su (lpluls001@gmail.com) """ -import sys, os.path as osp +import sys +from pathlib import Path -sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__)))) -from modules import * +sys.path.append(str(Path(__file__).parent.parent)) +from modules import TreeNode, list_to_tree, print_tree from collections import deque diff --git a/codes/python/chapter_tree/binary_tree_dfs.py b/codes/python/chapter_tree/binary_tree_dfs.py index 3bcef854..9b3488ad 100644 --- a/codes/python/chapter_tree/binary_tree_dfs.py +++ b/codes/python/chapter_tree/binary_tree_dfs.py @@ -4,10 +4,11 @@ Created Time: 2022-12-20 Author: a16su (lpluls001@gmail.com) """ -import sys, os.path as osp +import sys +from pathlib import Path -sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__)))) -from modules import * +sys.path.append(str(Path(__file__).parent.parent)) +from modules import TreeNode, list_to_tree, print_tree def pre_order(root: TreeNode | None):