hello-algo/codes/go/chapter_searching/linear_search_test.go
Yudong Jin 1c8b7ef559
refactor: Replace 结点 with 节点 (#452)
* Replace 结点 with 节点
Update the footnotes in the figures

* Update mindmap

* Reduce the size of the mindmap.png
2023-04-09 04:32:17 +08:00

26 lines
601 B
Go

// File: linear_search_test.go
// Created Time: 2022-11-25
// Author: Reanon (793584285@qq.com)
package chapter_searching
import (
"fmt"
"testing"
. "github.com/krahets/hello-algo/pkg"
)
func TestLinearSearch(t *testing.T) {
target := 3
nums := []int{1, 5, 3, 2, 4, 7, 5, 9, 10, 8}
// 在数组中执行线性查找
index := linearSearchArray(nums, target)
fmt.Println("目标元素 3 的索引 =", index)
// 在链表中执行线性查找
head := ArrayToLinkedList(nums)
node := linearSearchLinkedList(head, target)
fmt.Println("目标节点值 3 的对应节点对象为", node)
}