A 16 line implementation of the binary search algorithm in C#.
Which I used to create an ASCII table!
For further actions, you may consider blocking this person and/or reporting abuse
A 16 line implementation of the binary search algorithm in C#.
Which I used to create an ASCII table!
For further actions, you may consider blocking this person and/or reporting abuse
mohamed Tayel -
Rob -
Sukhpinder Singh -
Leandro Veiga -
Top comments (3)
Unfortunately this is not a valid binary search algorithm with log(n) complexity. left++ and right— changes search position by one and not by half of remaining items. You need to change left/right to middle+-1.
Fixed..I think
Yes, now it can find any character (from your list) in maximally 8 steps...
You can also enhance code a little... There is no need to use IComparable as a parameter to the Search method. You have generics and thus it would be better to have the parameter of type T. You can specify that "T" is IComparable:
public static int Search<T>(List<T> list, T val) where T : IComparable<T>