using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication5 { class Search { public static int Seqsearch(int[] a, int item) { int loc; bool found = false; for (loc = 0; loc < a.Length; loc++) if (a[loc] == item) { found = true; break; } if (found) return loc; else return -1; } public static int Binarysearch(int[] a, int item,int left,int right) { int mid = (left + right) / 2; if (right < left) return -1; else if (a[mid] ==item) return mid; else if (a[mid] > item) return Binarysearch(a, item, left, mid - 1); else return Binarysearch(a, item, mid+1, right); return -1; } static void Main(string[] args) { int[] a ={ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; int key = Seqsearch(a, 4); Console.WriteLine(key); key = Binarysearch(a,6,0,9); Console.WriteLine(key); } } }