public void Run(int[] tab) { for (int i = 1; i < tab.Length; i++) { int j = i; while (j > 0 && tab[j - 1] > tab[j]) { SortAlgorithms.swap(ref tab[j - 1], ref tab[j]); j--; } } }
public void Run(int[] tab) { bool swapped = true; while (swapped) { swapped = false; for (int i = 1; i < tab.Length; i++) { if (tab[i - 1] > tab[i]) { SortAlgorithms.swap(ref tab[i - 1], ref tab[i]); swapped = true; } } } }
public static int[] GenerateRandomArray(int len, int minValue) { int[] tab = new int[len]; Random rnd = new Random(); for (int i = 0; i < tab.Length; i++) { tab[i] = i + minValue; } for (int i = 0; i < tab.Length; i++) { int firstIdx = rnd.Next(tab.Length); int secondIdx = rnd.Next(tab.Length); if (firstIdx == secondIdx) { continue; } SortAlgorithms.swap(ref tab[firstIdx], ref tab[secondIdx]); } return(tab); }