public void SortResultOrderTest(IInputSample <int> inputSample) { if (inputSample.Samples.Length < 100) { sort.Sort(inputSample.Samples).Is(inputSample.Samples.OrderBy(x => x)); } }
public void Sort_SortEntireListCustomCompare() { int[] tempArray = new int[10]; testArray.CopyTo(tempArray, 0); customSort.Sort(tempArray); for (int i = 0; i < tempArray.Length; i++) { Assert.Equal(i, tempArray[i]); } }
public void Sort_AlternateSortEntireListCustomCompare() { var tempArray = (int[])testArraySmall.Clone(); customSort.Sort(tempArray); for (int i = 0; i < tempArray.Length; i++) { Assert.Equal(i, tempArray[i]); } }
public void Sort_SortEntireListDefaultCompare() { var tempArray = new int[10]; testArray.CopyTo(tempArray, 0); defaultSort.Sort(tempArray); int tempCount = tempArray.Length; for (int i = 0; i < tempCount; i++) { Assert.Equal(i, tempArray[i]); } }
private void RunSort(ISort <int> sort, IInputSample <int> input) { var array = input.Samples; // prerequites var keep = new int[array.Length]; ResetArray(ref array, ref keep); // run sort var after = sort.Sort(array); // validate sort.Statistics.IsSorted = after.SequenceEqual(validateArray); // result MarkDownOutputList.Add(new MarkdownOutput(sort.Statistics, input.InputType)); // Console Output var sortResult = sort.Statistics.IsSorted ? "Correct" : $@" Before : {keep.ToJoinedString(" ")} After : {after.ToJoinedString(" ")}"; var console = new ConsoleOutput(sort.Statistics, sortResult, input.InputType); Console.WriteLine(console.ToString()); // reset ResetArray(ref keep, ref array); }
public static T[] Sort(T[] data, SortType sortType, SortOrder order = default) { SortFactory <T> factory = new SortFactory <T>(); ISort <T> sorter = factory.GetSort(sortType); return(sorter.Sort(data, order)); }
public JaggedArraySorter(int[][] arr, ISort sorting, IRowExplorer explorer, bool ascending) { JaggetArray = arr; this.explorer = explorer; GetSortTargets(); sorting.Sort(JaggetArray, rowsTargets, ascending); }
static void MergeSortTest() { int[] datas = ints.ToArray(); sorter = new MergeSort <int>(); sorter.Sort(datas); Print(datas); }
public List <Vehicle> GetSortedVehicles(ISort algorithm, bool descending = false) { var cars = database.cars; algorithm.Sort(ref cars, descending); return(cars); }
static void Main(string[] args) { Priority priority; Console.WriteLine("What is your .txt file destination"); string dest = Console.ReadLine(); Console.WriteLine("Do you prioritze memory or speed? Memory:1|Speed:0"); priority = Enum.Parse <Priority>(Console.ReadLine()); while (!File.Exists(dest)) { Console.WriteLine("Wrong Input:What is your .txt file destination"); dest = Console.ReadLine(); } string [] data = ReadWriteTxt.Read(dest); FactorySort factory = new FactorySort(); ISort sort = factory.ChooseSort(data, priority); sort._data = data; sort.Sort(); string NewDest = dest.Remove(dest.Length - 4) + "_sorted.txt"; ReadWriteTxt.Write(NewDest, sort._data); }
List <List <Figure> > IGrouping.Grouping(List <Figure> list) { List <List <Figure> > Array = new List <List <Figure> >(); List <Figure> arr; Heir.Sort(list); double Max = FiguresListGenerator.GetMax(list); double step = Max / Number; (double Min, double Max)pair = (0, step); while (pair.Max <= Max) { arr = new List <Figure>(); foreach (Figure fg in list) { if (fg.area() >= pair.Min && fg.area() <= pair.Max) { arr.Add(fg); } } Array.Add(arr); pair.Min += step; pair.Max += step; } return(Array); }
static void QuickSortTest() { int[] datas = ints2.ToArray(); sorter = new QuickSort <int>(); sorter.Sort(datas); Print(datas); }
private static void Sort(ISort SortAlgorithm, ArrayTestBed origArrayTestBed, ArrayTestBed clonedArrayTestBed, string algorithmTitle) { //origArrayTestBed.DispayElements(); GC.Collect(); Metrics metric = new Metrics($"{algorithmTitle} Sort"); var result = SortAlgorithm.Sort(origArrayTestBed); metric.Dispose(); GC.Collect(); metric = new Metrics($"Reverse {algorithmTitle} Sort"); var result2 = SortAlgorithm.ReverseSort(clonedArrayTestBed); metric.Dispose(); origArrayTestBed.arr = result; clonedArrayTestBed.arr = result2; //origArrayTestBed.DispayElements(); //clonedArrayTestBed.DispayElements(); Console.WriteLine(); Console.WriteLine("======================================================================================================================================="); Console.WriteLine(); }
static void RadixSortTest() { int[] datas = ints2.ToArray(); sorter = new RadixSort(); sorter.Sort(datas); Print(((RadixSort)sorter).data); }
private static void NoMessages() { bool getImplementations = true; while (getImplementations) { PrintMessageYellow("Las implementaciones disponibles son: ", true); var implementations = loadAssembly.GetImplementations(); for (int i = 0; i < implementations.Count(); i++) { var implementation = implementations.ElementAt(i); Console.WriteLine(String.Format("{0}->{1}", i + 1, implementation.FullName)); } Console.Write("Seleccione una: "); int.TryParse(Console.ReadLine(), out int indexImplementation); ISort implementationSelected = loadAssembly.GetImplementation(indexImplementation - 1); implementationSelected.Sort(ref numbers); Console.WriteLine(String.Join(",", numbers.ToArray())); Console.WriteLine(); Console.ReadLine(); } PrintMessageYellow("Hasta la proxima forastero"); Console.ReadLine(); }
private static Tuple <double, double, bool> Run(ISort <MyKeyValue <int, string> > sort, int numberOfItems, int arrayPreparationIndex) { MyKeyValue <int, string>[] numbers = null; Stopwatch wallClock = new Stopwatch(); ProcessUserTime processUserTime = new ProcessUserTime(); switch (arrayPreparationIndex) { case 0: numbers = ArrayExtensions.CreateOrderedMKVArray(numberOfItems); break; case 1: numbers = ArrayExtensions.CreateReverseOrderedMKVArray(numberOfItems); break; case 2: numbers = ArrayExtensions.CreateRandomMKVArray(numberOfItems, new Random()); break; } // Measure the sorting. wallClock.Restart(); processUserTime.Restart(); sort.Sort(numbers); processUserTime.Stop(); wallClock.Stop(); return (new Tuple <double, double, bool>(wallClock.Elapsed.TotalSeconds, processUserTime.ElapsedTotalSeconds, ArrayExtensions.VerifySorted <MyKeyValue <int, string> >(numbers))); }
public void Sort() { foreach (var employee in _sortStrategy.Sort(employees)) { Console.WriteLine($"Employee name : {employee.Name}, Age: {employee.Age}, Salary:{employee.Salary}"); } }
public SortingResult SortingTime(ISort sort, int[] source) { var timeBefore = DateTime.Now; var array = sort.Sort(source); var timeAfter = DateTime.Now; return(new SortingResult((timeAfter - timeBefore).Milliseconds, array)); }
private void SortAndShow <T>(T[] array, ISort sorter) where T : IComparable { Debug.Log("排序前:"); LogArrayData(array); sorter.Sort(array); Debug.Log("排序后:"); LogArrayData(array); }
static void SortDesc <T>(ISort sort, T[] array) where T : IComparable <T> { Console.WriteLine("按降序排"); Print(true, array); sort.Sort(array, false); Print(false, array); Console.WriteLine(); }
static void Sorts(ISort sorter) { int[] test = new int[] { 8, 30, 1, 2, 5, 6 }; int[] result = sorter.Sort(test); System.Console.WriteLine(string.Join(", ", result)); }
private static void PrintSort <TItem>(Type sortGenericClass, TItem[] items) where TItem : IComparable <TItem> { Type sortClass = sortGenericClass.MakeGenericType(typeof(int)); ISort <TItem> sortInstance = (ISort <TItem>)Activator.CreateInstance(sortClass, new object[0]); PrintItems("Before: ", items); TItem[] sortedItems = sortInstance.Sort(items); PrintItems("After: ", items); }
public string SortInputStringChar(string inputString) { if (string.IsNullOrEmpty(inputString)) { return(null); } return(_sort.Sort(inputString)); }
private static void PerfSort(int[] input, ISort<int[]> sortAlgorithm, string type) { Console.WriteLine(string.Format("{0} sorting started", type)); var watch = Stopwatch.StartNew(); sortAlgorithm.Sort(input); Console.WriteLine(string.Format("{0} sorting finished in {1} miliseconds", type, watch.ElapsedMilliseconds)); }
public List <int[]> FindCombinationSum(int sum) { _arr = _sortHelper.Sort(_arr); List <int> v = new List <int>(); PerformUnitWork(sum, _arr.Length, v); return(consoleResult); }
static void ShellSortTest() { int[] datas = ints.ToArray(); sorter = new ShellSort <int>(); sorter.Sort(datas); Print(datas); // System.Console.WriteLine(Assert(datas)); }
private static void ThreadSort(ISort sortAlg, int[] dataSet) { sortAlg.Sort(dataSet); lock (countLock) { finishedThreads++; } }
private void MeasureSorter(ISort sorter, int[] s) { Trace.WriteLine("Sort type: " + sorter.GetType().Name); Trace.WriteLine("Items to sort: " + s.Length); var stopwatch = Stopwatch.StartNew(); sorter.Sort(s); stopwatch.Stop(); Trace.WriteLine("Result time: " + stopwatch.Elapsed); }
private static void Sort(ISort <int> sorter, int[] array) { stopwatch.Start(); sorter.Sort(array); stopwatch.Stop(); Console.WriteLine("{0} - {1:00} ms", sorter.Name, stopwatch.Elapsed.TotalMilliseconds); stopwatch.Reset(); }
public void Sort() { ISort sortAlg = SortFactory.CreateSort(SortType.HeapSort); for (int i = 0; i < setsCount; i++) { int[] copy = dataSet.Select(a => a).ToArray(); sortAlg.Sort(copy); } }
public void TestSort(ISort sort) { int[] a = new int[1000]; int[] b = new int[100000]; TestElement[] c = new TestElement[1000]; TestElement[] d = new TestElement[100000]; Array.Copy(smallTestIntegerArray, a, smallTestIntegerArray.Length); Array.Copy(bigTestIntegerArray, b, bigTestIntegerArray.Length); Array.Copy(smallTestObjectArray, c, smallTestObjectArray.Length); Array.Copy(bigTestObjectArray, d, bigTestObjectArray.Length); sort.Sort <int>(a, (x, y) => x.CompareTo(y)); Assert.IsTrue(CheckSort(a, (x, y) => x.CompareTo(y))); sort.Sort <int>(b, (x, y) => x.CompareTo(y)); Assert.IsTrue(CheckSort(b, (x, y) => x.CompareTo(y))); int CompareTestElements(TestElement x, TestElement y) { if (x.a == y.a) { return(0); } if (x.a > y.a) { return(1); } if (x.a < y.a) { return(-1); } return(0); } sort.Sort <TestElement>(c, (x, y) => CompareTestElements(x, y)); Assert.IsTrue(CheckSort(c, (x, y) => CompareTestElements(x, y))); sort.Sort <TestElement>(d, (x, y) => CompareTestElements(x, y)); Assert.IsTrue(CheckSort(d, (x, y) => CompareTestElements(x, y))); }
private static void GetSorted(ISort sortEngine, int[] numbers) { int[] clonedNumbers = new int[numbers.Length]; numbers.ToList().CopyTo(clonedNumbers); int[] sortedNumbers = sortEngine.Sort(clonedNumbers); Console.WriteLine($"Sorted by {sortEngine.Name}({Validate(sortedNumbers)}): {string.Join(", ", sortedNumbers)}"); Console.WriteLine("----------------------------------------------------------------------"); Console.WriteLine(); }
static void SortPerfomance(int[] array, ISort sortAlgorithm) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); array = sortAlgorithm.Sort<int>(array, Comparer<int>.Default); stopWatch.Stop(); TimeSpan t = stopWatch.Elapsed; string elapsedTime = String.Format('\t' + "{0:00}:{1:00}:{2:00}.{3:00}", t.Hours, t.Minutes, t.Seconds, t.Milliseconds / 10); Console.WriteLine(elapsedTime); }
static void OuterSortTest() { List <int> datas = new List <int>(); for (int i = 50; i > 0; i--) { datas.Add(i); } sorter = new OuterSort(); var res = sorter.Sort(datas.ToArray()); Print(res); }
public static void Sort(ISort sort, ArrayList inArray) { var result = sort.Sort(inArray); Console.WriteLine(result.ToString().Split(' ')); }
private static void Sort(ISort<int> sorter, int[] array) { stopwatch.Start(); sorter.Sort(array); stopwatch.Stop(); Console.WriteLine("{0} - {1:00} ms", sorter.Name, stopwatch.Elapsed.TotalMilliseconds); stopwatch.Reset(); }