You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hello-algo/codes/go/chapter_computational_compl.../recursion_test.go

27 lines
555 B

// File: recursion_test.go
// Created Time: 2023-08-28
// Author: Reanon (793584285@qq.com)
package chapter_computational_complexity
import (
"fmt"
"testing"
)
/* Driver Code */
func TestRecursion(t *testing.T) {
n := 5
res := recur(n)
fmt.Println("\n递归函数的求和结果 res = ", res)
res = forLoopRecur(n)
fmt.Println("\n使用迭代模拟递归求和结果 res = ", res)
res = tailRecur(n, 0)
fmt.Println("\n尾递归函数的求和结果 res = ", res)
res = fib(n)
fmt.Println("\n斐波那契数列的第", n, "项为", res)
}