Search here for all the info you want in this Blog

linear search algorithm


public class LinearSearch{    
public static int linearSearch(int[] arr, int key){    
        for(int i=0;i < arr.length;i++){    
            if(arr[i] == key){    
                return i;    
            }    
        }    
        return -1;    
    }    
    public static void main(String a[]){    
        int[] a1= {10,20,30,50,60,70,80};    
        int key = 50;    
        System.out.println(key+" found at index: "+linearSearch(a1, key));    
    }    
}

No comments:

Post a Comment