using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ch5_4
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        int[] array = new int[18] { 5, 10, 15, 20, 25, 30, 35, 40,
                         45, 50, 55, 60, 65, 70, 75, 80, 85, 90 }; 
        private void Form1_Load(object sender, EventArgs e) 
        {

        }

        private void Sequential_Click(object sender, EventArgs e)
        {
            int num = Convert.ToInt32(textBox1.Text);
            bool found = false ;
            for (int i = 0; i < array.Length && !found; i++)
                if (num == array[i])
                    found = true;
            if (found)
                label2.Text = "Number " + num.ToString() + " found";
            else
                label2.Text = "Number " + num.ToString() + " not found";
        }

        private void Binary_Click(object sender, EventArgs e)
        {
            int num = Convert.ToInt32(textBox1.Text);
            bool found = false;
            int mid, low = 0, high = array.Length - 1;
            while (high >= low && !found)
            {
                mid = (int)(low + high) / 2;
                if (array[mid] == num)
                    found = true;
                else if (num > array[mid])
                    low = mid + 1;
                else
                    high = mid - 1;
            }
            if (found)
                label2.Text = "Number " + num.ToString() + " found";
            else
                label2.Text = "Number " + num.ToString() + " not found";
        }
    }
}
