C# program to Insertion Sort
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class Main
{
public static void InsertionSort<T>(this IList<T> list, Comparison<T> comparison)
{
int count = list.Count;
for (int j = 1; j < count; j++)
{
T key = list[j];
int i = j - 1;
for (; i >= 0 && comparison(list[i], key) > 0; i--)
list[i + 1] = list[i];
if (i != j - 1)
list[i + 1] = key;
}
}
}
No comments