-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
61 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
name = "LinearSearch" | ||
uuid = "5da00125-5d9f-4369-a127-aa7d26c58302" | ||
authors = ["Yueh-Hua Tu <[email protected]>"] | ||
version = "0.1.0" | ||
|
||
[compat] | ||
julia = "1.4" | ||
|
||
[extras] | ||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | ||
|
||
[targets] | ||
test = ["Test"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# 線性搜尋法 | ||
|
||
線性搜尋法是搜尋演算法中最簡單也最直覺的演算法,可以用於線性的資料結構的搜尋,例如:一維陣列(array)、串列(list)、堆疊(stack)或是佇列(queue)。一般搜尋演算法需要輸入一個陣列,搜尋陣列中的特定元素,並且回傳特定元素的索引位置,如果沒有找到,則回傳 -1。線性搜尋法會從第一個元素開始進行比對,如果並不是搜尋目標,則會往下一個元素搜尋,直到陣列被搜尋完畢為止。 | ||
|
||
## 測試 | ||
|
||
```julia | ||
a = [1, 5, 6, 2, 7, 3, 30, 70, 40] | ||
@test linearsearch(a, 1) == 1 | ||
@test linearsearch(a, 40) == 9 | ||
@test linearsearch(a, 7) == 5 | ||
@test linearsearch(a, 100) == -1 | ||
``` | ||
|
||
### 測試資料 | ||
|
||
```julia | ||
a = [1, 5, 6, 2, 7, 3, 30, 70, 40] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module LinearSearch | ||
|
||
src = [ | ||
] | ||
|
||
for s = src | ||
include("$(s).jl") | ||
end | ||
|
||
end # module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using LinearSearch | ||
using Test | ||
|
||
tests = [ | ||
] | ||
|
||
@testset "LinearSearch.jl" begin | ||
for t in tests | ||
include("$(t).jl") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters