Skip to content

Commit 1e32fb1

Browse files
authored
Create Linear Search.java
1 parent fb1a86b commit 1e32fb1

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/******************************************************************************
2+
3+
Online Java Compiler.
4+
Code, Compile, Run and Debug java program online.
5+
Write your code in this editor and press "Run" button to execute it.
6+
7+
*******************************************************************************/
8+
9+
public class Main
10+
{
11+
static boolean linearSearch(int[] arr, int left, int right, int key){
12+
13+
// base case
14+
15+
if(right < left){
16+
return false;
17+
}
18+
19+
if(arr[left] == key){
20+
return true;
21+
} else {
22+
return remainingPart;
23+
}
24+
25+
26+
}
27+
28+
public static void main(String[] args) {
29+
30+
int[] arr = {2, 4, 1, 8, 0};
31+
32+
int size = 5;
33+
int key = 2;
34+
35+
boolean ans = linearSearch(arr, size, key);
36+
37+
if(ans){
38+
System.out.println("ELEMENT PRESENT");
39+
} else {
40+
System.out.println("ELEMENT NOT PRESENT");
41+
}
42+
}
43+
}
44+
45+
46+
// to be corrected

0 commit comments

Comments
 (0)