/*Сортировка массива из трёх элементов. После сортировки второй элемент больше первого, третий больше второго*/ public void SortSimpleArray() { var array = QSort.GenerateArray(3); QSort.QuickSort(array); Assert.IsTrue(array[0] < array[1] && array[1] < array[2], "Simple array sorting"); }
public void PutPair(object key, object value) { var hashdKey = key.GetHashCode(); int id; if ((id = BSearch.BinarySearch(keys, hashdKey)) != -1) { values[id] = value; } else if (num < Length) { keys[num] = hashdKey; values[num] = value; num++; } else { Console.WriteLine("(!) Переполнение таблицы. err: a[{0}] = {1}", key, value); return; } if (!QSort.IsSortedArray(keys)) { QSort.QuickSortAssociative(keys, values); } }
static void Main(string[] args) { QSort qs = new QSort(); int tamaño; int dato; Console.Write("Tamaño del arreglo: "); tamaño = int.Parse(Console.ReadLine()); int[] arreglo = new int[tamaño]; for (int n = 0; n < tamaño; ++n) { Console.Write("Ingresa el dato numero {0}: ", n + 1); dato = int.Parse(Console.ReadLine()); arreglo[n] = dato; } qs.quicksort(arreglo, tamaño); Console.WriteLine("Impresion de datos ordenados"); for (int n = 0; n < tamaño; ++n) { Console.Write("{0} ", arreglo[n]); } }
public void SortHundredArray() { var array = new int[100]; QSort.QuickSort(array); foreach (var n in array) { Assert.IsTrue(n == array[0]); } }
public void SortBigArray() { var array = QSort.GenerateArray(1500000000); QSort.QuickSort(array); for (var i = 1; i < array.Length; i++) { Assert.IsTrue(array[i - 1] < array[i]); } }
public void SortThousandArray() { var array = QSort.GenerateArray(1000); var indexes = QSort.GenerateArray(20, array.Length); QSort.QuickSort(array); for (var i = 0; i < indexes.Length; i += 2) { Assert.IsTrue((array[indexes[i]] < array[indexes[1 + i]] && indexes[i] < indexes[1 + i]) || (array[indexes[i]] > array[indexes[1 + i]] && indexes[i] > indexes[1 + i]), "Normal array sorting"); } }
static void Main(string[] args) { // First array MyArr one = new MyArr(); int[] array = one.GetArr(); Console.Write("Unsorted array: "); foreach (var item in array) { Console.Write(item + " "); } Console.WriteLine(); // Merge sorting MSort.MergeSort(array); Console.Write("Merge sorted array: "); foreach (var item in array) { Console.Write(item + " "); } Console.WriteLine(); // Second array RandArr two = new RandArr(); array = two.GetArr(); Console.Write("Unsorted array: "); foreach (var item in array) { Console.Write(item + " "); } Console.WriteLine(); // Quick sorting QSort.QuickSort(array); Console.Write("Quick sorted array: "); foreach (var item in array) { Console.Write(item + " "); } Console.WriteLine(); Console.ReadKey(); }
protected void AddQuerySort(Query q, string sortFld) { if (q.Sort != null) { var newSort = new QSort[q.Sort.Length + 1]; Array.Copy(q.Sort, newSort, q.Sort.Length); newSort[q.Sort.Length] = sortFld; q.Sort = newSort; } else { q.Sort = new QSort[] { sortFld }; } }
static void Main(string[] args) { var original = new List <int>(); var random = new Random(); for (int i = 0; i < 20; i++) { original.Add(random.Next() % 25); } PrintEnumerable <int>(original); var toSort = ListModule.OfSeq(original); var sorted = QSort.sort <int>(toSort); PrintEnumerable <int>(sorted); }
static void Main(string[] args) { Console.WriteLine("Тестирование MergeSort"); int[] arrayOne = new int[] { 5, -10, 15, 20, 50, 1, 0, 0, -3, -20, 100 }; MergeSort.Sort(arrayOne); if (Check(arrayOne, 0, arrayOne.Length - 1)) { Console.WriteLine("Полная сортировка\n"); } Print(arrayOne); int[] arrayTwo = new int[] { 80, -20, 25, 5 }; MergeSort.Sort(arrayTwo, 0, 1); if (Check(arrayOne, 0, 1)) { Console.WriteLine("Частичная сортировка\n"); } Print(arrayTwo); int[] arrayThree = { 50 }; MergeSort.Sort(arrayThree); Console.WriteLine("Обработка массива из одного элемента\n"); Print(arrayThree); Console.WriteLine("Тестирование QSort"); int[] arrayFour = new int[] { 15, -100, 15, 12, 25, 1, -3, 0, -8, -20, 63 }; QSort.Sort(arrayFour); if (Check(arrayFour, 0, arrayFour.Length - 1)) { Console.WriteLine("Полная сортировка\n"); } Print(arrayFour); int[] arrayFive = new int[] { 0, -1, 15, 19 }; QSort.Sort(arrayFive, 0, 1); if (Check(arrayFive, 0, 1)) { Console.WriteLine("Частичная сортировка\n"); } Print(arrayFive); int[] arraySix = { 10 }; QSort.Sort(arraySix); Console.WriteLine("Обработка массива из одного элемента\n"); Print(arraySix); Console.ReadKey(); }
private static void FindNearest(int[] digitals, int size) { for (int i = (size - 1); i > 0; i--) { QSort.Sort(digitals, i, size - 1); for (int j = i; j < size; j++) { if (digitals[i - 1] < digitals[j]) { int temp = digitals[i - 1]; digitals[i - 1] = digitals[j]; digitals[j] = temp; return; } } } }
static void Main(string[] args) { Console.WriteLine("Enter size array:"); int sizeArray = Convert.ToInt32(Console.ReadLine()); ElementType[] mas = new ElementType[sizeArray]; Random rand = new Random(DateTime.Now.Millisecond); for (int i = 0; i < sizeArray; i++) { mas[i] = new ElementType(sizeArray, rand); } Console.WriteLine("Not sort array:"); printMas(mas, sizeArray); QSort.Qsort(mas, 0, sizeArray - 1); Console.WriteLine("Sorted array to the first element of the column"); printMas(mas, sizeArray); }
static void Main(string[] args) { System.Console.WriteLine("Enter size of array:"); string input = Console.ReadLine(); int sizeArray = Convert.ToInt32(input); ElementType[] mas = new ElementType[sizeArray]; Random rand = new Random(DateTime.Now.Millisecond); for (int i = 0; i < sizeArray; i++) { mas[i] = new ElementType(rand.Next(0, 100)); } Console.WriteLine("Not sort mas:"); printMas(mas, sizeArray); QSort.Qsort(mas, 0, sizeArray - 1); Console.WriteLine("Sort mas:"); printMas(mas, sizeArray); }
public void test_QSortField() { QSort fld = (QSort)"name"; Assert.AreEqual(fld.Field.Name, "name", "QSortField parse error"); Assert.AreEqual(fld.SortDirection, ListSortDirection.Ascending, "QSortField parse error"); fld = (QSort)"email desc "; Assert.AreEqual(fld.Field.Name, "email", "QSortField parse error"); Assert.AreEqual(fld.SortDirection, ListSortDirection.Descending, "QSortField parse error"); fld = (QSort)"email desc "; Assert.AreEqual(fld.Field.Name, "email", "QSortField parse error"); Assert.AreEqual(fld.SortDirection, ListSortDirection.Descending, "QSortField parse error"); fld = (QSort)" email desc "; Assert.AreEqual(fld.Field.Name, "email", "QSortField parse error"); Assert.AreEqual(fld.SortDirection, ListSortDirection.Descending, "QSortField parse error"); fld = (QSort)"position asc"; Assert.AreEqual(fld.Field.Name, "position", "QSortField parse error"); Assert.AreEqual(fld.SortDirection, ListSortDirection.Ascending, "QSortField parse error"); }
public static void QuickSort() { int[] arr; FileToArr(out arr); Console.WriteLine("- Danh sach ban dau lay tu File:"); Console.WriteLine("[{0}]", string.Join(", ", arr)); Console.WriteLine("- Danh sach sau khi duoc sap xep:"); var sw = Stopwatch.StartNew(); var sorter = new QSort <int>(arr); sorter.QuickSort(0, arr.Length - 1); sw.Stop(); Console.WriteLine("[{0}]", string.Join(", ", arr)); Console.WriteLine("Time taken QuickSort: {0} ms", sw.Elapsed.TotalMilliseconds); var sw1 = Stopwatch.StartNew(); var sorter1 = new QSort <int>(arr); sorter1.QuickSortDescending(0, arr.Length - 1); sw1.Stop(); Console.WriteLine("[{0}]", string.Join(", ", arr)); Console.WriteLine("Time taken QuickSort: {0} ms", sw1.Elapsed.TotalMilliseconds); Console.ReadKey(true); }
public void QSortField() { QSort fld = (QSort)"name"; Assert.Equal(fld.Field.Name, "name"); Assert.Equal(fld.SortDirection, ListSortDirection.Ascending); fld = (QSort)"email desc "; Assert.Equal(fld.Field.Name, "email"); Assert.Equal(fld.SortDirection, ListSortDirection.Descending); fld = (QSort)"email desc "; Assert.Equal(fld.Field.Name, "email"); Assert.Equal(fld.SortDirection, ListSortDirection.Descending); fld = (QSort)" email desc "; Assert.Equal(fld.Field.Name, "email"); Assert.Equal(fld.SortDirection, ListSortDirection.Descending); fld = (QSort)"position asc"; Assert.Equal(fld.Field.Name, "position"); Assert.Equal(fld.SortDirection, ListSortDirection.Ascending); }
public void SortEmptyArray() { var array = new int[0]; QSort.QuickSort(array); }
public void Setup() { qSort = new QSort(); }