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