Skip to content

Commit c7c2078

Browse files
committedNov 26, 2017
・Implement 'Linear Serach' function in Ruby
・Modify 'Linear Search' function in Java
1 parent db39c54 commit c7c2078

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed
 

‎linear_search/LinearSearch.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@
66
public class LinearSearch {
77

88
public static void main(String[] args) {
9-
Integer inputArray[] = {13, 5, 17, 2, 11, 35};
9+
Integer inputArr[] = {13, 5, 17, 2, 11, 35};
1010
Integer targetNum = 11;
11-
boolean targetFoundFlg = false;
11+
boolean targetFindFlg = false;
1212

1313
long start = System.nanoTime();
1414

15-
for(Integer inputNum : inputArray) {
15+
for(Integer inputNum : inputArr) {
1616
if(targetNum == inputNum) {
17-
targetFoundFlg = true;
17+
targetFindFlg = true;
1818
System.out.println("The target number(" + targetNum + ") was found.");
1919
break;
2020
}
2121
}
2222

23-
if(targetFoundFlg != true) {
23+
if(targetFindFlg != true) {
2424
System.out.println("The target number (" + targetNum + ") was not found...");
2525
}
2626

‎linear_search/LinearSearch.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
require 'time'
2+
3+
class LinearSearch
4+
input_arr = [13, 5, 17, 2, 11, 35]
5+
target_num = 11
6+
target_find_flg = false
7+
8+
start_time = Time.now
9+
10+
input_arr.each do |input_num|
11+
if target_num == input_num
12+
target_find_flg = true
13+
puts "The target number(#{target_num}) was found."
14+
break;
15+
end
16+
end
17+
18+
if target_find_flg == false
19+
puts "The target number(#{target_num}) was not found..."
20+
end
21+
22+
end_time = Time.now
23+
24+
puts "Exec time: #{(end_time - start_time) * 100000} ms"
25+
end

0 commit comments

Comments
 (0)