Skip to content

Commit 1b49000

Browse files
authored
linear searching
1 parent 8203398 commit 1b49000

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

searching/linear_searching.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Program for Linear Searching in JAVA
3+
* return the index of searched element if found,
4+
* else returns -1.
5+
*/
6+
public class linear_searching
7+
{
8+
public static int search(int[] arr, int val)
9+
{
10+
int res;
11+
for (res = 0; res < arr.length; ++res) {
12+
if (arr[res] == val) {
13+
return res;
14+
}
15+
}
16+
return -1;
17+
}
18+
}

0 commit comments

Comments
 (0)