deleriumbg

Untitled

Mar 12th, 2019
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.23 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace demo2
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<int> ints = new List<int>() {1, 4, 6, 7, 11, 13};
  12.             ints.Sort();
  13.             Console.WriteLine(BinarySort(ints, 8));
  14.            
  15.         }
  16.  
  17.         private static int BinarySort(List<int> ints, int num)
  18.         {
  19.             int middle = ints[ints.Count / 2];
  20.             if (num < middle)
  21.             {
  22.                 ints = ints.Take(ints.Count / 2).ToList();
  23.                 return BinarySort(ints, num);
  24.             }
  25.             if (num > middle)
  26.             {
  27.                 ints = ints.Skip(ints.Count / 2).Take(ints.Count / 2).ToList();
  28.                 return BinarySort(ints, num);
  29.             }
  30.             return middle;
  31.         }
  32.  
  33.         private static T MinValue<T>(List<T> ints) where T : IComparable<T>
  34.         {
  35.  
  36.             T currentMin = ints[0];
  37.             for (int i = 0; i < ints.Count; i++)
  38.             {
  39.                 if (ints[i].CompareTo(currentMin) > 0)
  40.                 {
  41.                     currentMin = ints[i];
  42.                 }
  43.             }
  44.  
  45.             return currentMin;
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment