private void binarySearchBtn_Click(object sender, EventArgs e) { int[] dizi = RandomDiziOlustur(100); //DiziyiYazdir(dizi); BinarySearch BS = new BinarySearch(); int indis = BS.Search(dizi, Convert.ToInt32(txtArananSayi.Text)); if (indis == -1) { MessageBox.Show("Aranan sayı bulunamadı..."); } else { MessageBox.Show("Arana sayı bulundu, dizi indisi: " + indis); } }
static void Main(string[] _) { var rnd = new Random(); var arrSize = rnd.Next(1, 100); int[] arr = Enumerable.Repeat(0, arrSize).Select(x => rnd.Next(int.MinValue, int.MaxValue)).OrderBy(x => x).ToArray(); var itemToSearch = arr[rnd.Next(0, arrSize)]; var ls = LinearSearch.Search(arr, itemToSearch); var bs = BinarySearch.Search(arr, itemToSearch); var js = JumpSearch.Search(arr, itemToSearch); var es = ExponentialSearch.Search(arr, itemToSearch); var ts = TernarySearch.Search(arr, itemToSearch); Assert.Equal(ls, bs); Assert.Equal(bs, js); Assert.Equal(js, es); Assert.Equal(es, ts); }