Add cpp codes for the chapter

computational complexity, sorting, searching.
This commit is contained in:
Yudong Jin
2022-11-27 04:20:30 +08:00
parent 431a0f6caf
commit 19a4ccd86a
32 changed files with 1362 additions and 52 deletions

View File

@@ -37,7 +37,7 @@ def linear(n):
""" 线性阶(递归实现) """
def linearRecur(n):
print("递归 n = ", n)
print("递归 n =", n)
if n == 1: return
linearRecur(n - 1)
@@ -50,7 +50,7 @@ def quadratic(n):
def quadratic_recur(n):
if n <= 0: return 0
nums = [0] * n
print("递归 n = {} 中的 nums 长度 = {}".format(n, len(nums)))
print("递归 n =", n, "中的 nums 长度 =", len(nums))
return quadratic_recur(n - 1)
""" 指数阶(建立满二叉树) """

View File

@@ -52,6 +52,6 @@ def merge_sort(nums, left, right):
""" Driver Code """
if __name__ == '__main__':
nums = [4, 1, 3, 1, 5, 2]
nums = [ 7, 3, 2, 6, 0, 1, 5, 4 ]
merge_sort(nums, 0, len(nums) - 1)
print("归并排序完成后 nums =", nums)