Linear search is used for searching an item in a list of items,such as in Array.It is not efficient when compared to other ways of searching item in an array.
public static int LinearSearch(int[] A,int val) { for(int i=0;i<A.Length;i++) { if(A[i]==val) return i; } return-1; }
Leave a Reply