mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-07 13:14:19 +00:00
772183705e
* Add Russian docs site baseline * Add Russian localized codebase * Polish Russian code wording * Update ru code translation. * Update code translation and chapter covers. * Fix pythontutor extraction. * Add README and landing page. * placeholder of profiles * Use figures of English version * Remove chapter paperbook
27 lines
713 B
Go
27 lines
713 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)
|
|
}
|