Linear Search
7
2 13 4 1 3 6 28
3
4
public class Solution {
public static int linearSearch(int arr[], int x) {
int l=arr.length;
int pos=0;
for(int i=0;i<l;i++)
{
if(arr[i]==x)
{
pos=i;
}
}
if(pos==0)
{
return -1;
}
return pos;
}
}
Comments
Post a Comment