Skip to content

Commit

Permalink
Add LinearSearch
Browse files Browse the repository at this point in the history
  • Loading branch information
yuehhua committed Apr 23, 2020
1 parent c6f2a28 commit 4e1075a
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 7 deletions.
13 changes: 13 additions & 0 deletions LinearSearch/Project.toml
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"]
19 changes: 19 additions & 0 deletions LinearSearch/README.md
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]
```
10 changes: 10 additions & 0 deletions LinearSearch/src/LinearSearch.jl
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
11 changes: 11 additions & 0 deletions LinearSearch/test/runtests.jl
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
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,27 @@

## 初階

[費氏數列](Fibonacci/)

[Chaos Game](ChaosGame/)
* [費氏數列](Fibonacci/)
* [Chaos Game](ChaosGame/)

### 數值演算法

[蒙地卡羅方法](MonteCarlo/)
* [蒙地卡羅方法](MonteCarlo/)

### 簡單資料結構

### 排序演算法

[氣泡排序法](BubbleSort/)
* [氣泡排序法](BubbleSort/)

### 搜尋演算法

* [線性搜尋法](LinearSearch/)

## 中階

[尾遞迴費氏數列](TailRecursiveFibonacci/)
[動態規劃費氏數列](DynamicProgrammingFibonacci/)
* [尾遞迴費氏數列](TailRecursiveFibonacci/)
* [動態規劃費氏數列](DynamicProgrammingFibonacci/)

### 數值演算法

Expand Down

0 comments on commit 4e1075a

Please sign in to comment.