Skip to content

Commit c987963

Browse files
committed
added iterative linear search in java
1 parent a414160 commit c987963

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/java/LinearSearchIterative.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
public class LinearSearchIterative{
2+
public static void main(String[] args) {
3+
int array_1[] = {1,2,40,233,78,83,456};
4+
System.out.println(LinearSearch(array_1, 40));
5+
System.out.println(LinearSearch(array_1, 3));
6+
}
7+
public static int LinearSearch(int array[], int value){
8+
for(int i = 0 ; i < array.length ; i ++){
9+
if(array[i] == value){
10+
return i;
11+
}
12+
}
13+
return -1;
14+
}
15+
}

0 commit comments

Comments
 (0)