Here is what im trying to code in c# (algorithm 2.4)
here is where i am at
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace binary
{
class Program
{
static void Main()
{
var list = new List
int lower = 1;
int upper = list.Count;
int middle = (int)Math.Sqrt(upper);
int[] binary = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
foreach (int X in binary)
{
if (lower == upper)
{
if (X ==list[lower])
{
Console.WriteLine("{0} was found at index {1}", X, lower);
}
else { Console.WriteLine("0"); }
}
else
{
middle = (lower + upper) / 2;
if (X > list[middle])
{
Console.WriteLine("list {0} mid {1} upper {2} and x{3}",list,middle+1,upper, X);
}
else { Console.WriteLine("list {0} mid {1} upper {2} and x{3}",list,middle+1,upper, X);}
}
}
Console.ReadKey();
}
}
}
Francis SusaimichaelPosted Feb 8, 2015, 2:58 AM
http://www.c-sharpcorner.com/Blogs/14528/binary-search-implementation-using-C-Sharp.aspx