mirror of
https://github.com/krahets/hello-algo.git
synced 2024-12-27 03:16:29 +08:00
ebf9024136
the chapter of stack and queue, the chapter of tree.
26 lines
599 B
Go
26 lines
599 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 := linerSearchArray(nums, target)
|
|
fmt.Println("目标元素 3 的索引 =", index)
|
|
|
|
// 在链表中执行线性查找
|
|
head := ArrayToLinkedList(nums)
|
|
node := linerSearchLinkedList(head, target)
|
|
fmt.Println("目标结点值 3 的对应结点对象为", node)
|
|
}
|