Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace demo2
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<int> ints = new List<int>() {1, 4, 6, 7, 11, 13};
- ints.Sort();
- Console.WriteLine(BinarySort(ints, 8));
- }
- private static int BinarySort(List<int> ints, int num)
- {
- int middle = ints[ints.Count / 2];
- if (num < middle)
- {
- ints = ints.Take(ints.Count / 2).ToList();
- return BinarySort(ints, num);
- }
- if (num > middle)
- {
- ints = ints.Skip(ints.Count / 2).Take(ints.Count / 2).ToList();
- return BinarySort(ints, num);
- }
- return middle;
- }
- private static T MinValue<T>(List<T> ints) where T : IComparable<T>
- {
- T currentMin = ints[0];
- for (int i = 0; i < ints.Count; i++)
- {
- if (ints[i].CompareTo(currentMin) > 0)
- {
- currentMin = ints[i];
- }
- }
- return currentMin;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment