static void TeeMittaukset(SortDelegate sortDelegate) { CreateArrayDelegate randomOrder = new CreateArrayDelegate(CreateRandomOrderTable); CreateArrayDelegate ascOrder = new CreateArrayDelegate(CreateAscendingTable); CreateArrayDelegate descOrder = new CreateArrayDelegate(CreateDescendingTable); int arrSize = 500000; int[] num = new int[arrSize]; // järjestämätön taulukko num = CreateRandomArray(randomOrder, arrSize); var elapsedTime = MittaaAika(sortDelegate, num); Console.WriteLine("Järjestämätön taulukko \t aika: {0}", elapsedTime); // nouseva järjestys num = CreateRandomArray(ascOrder, arrSize); elapsedTime = MittaaAika(sortDelegate, num); Console.WriteLine("Nouseva taulukko \t aika: {0}", elapsedTime); // laskeva järjestys num = CreateRandomArray(descOrder, arrSize); elapsedTime = MittaaAika(sortDelegate, num); Console.WriteLine("Laskeva taulukko \t aika: {0}", elapsedTime); }
public void BubleSort(SortDelegate func, bool reverse = false) { ListView.ListViewItemCollection col = null; listView1.Invoke(new Action(() => col = listView1.Items)); ListViewItem temp; ListViewItem temp2; for (int i = 0; i < col.Count; i++) { for (int j = i + 1; j < col.Count; j++) { if (func(col[i], col[j], reverse)) { temp = listView1.Items[i]; temp2 = listView1.Items[j]; listView1.Invoke(new Action(() => listView1.Items.RemoveAt(i))); listView1.Invoke(new Action(() => listView1.Items.RemoveAt(j - 1))); listView1.Invoke(new Action(() => listView1.Items.Insert(i, temp2))); listView1.Invoke(new Action(() => listView1.Items.Insert(j, temp))); } } } }
public void Sort(SortDelegate sorter) { // Sort implementation omitted ;-) // Sample of using the delegate instance: int result = sorter(_employees[0], _employees[1]); }
static TimeSpan MittaaAika(SortDelegate sortDelegate, int[] num) { Stopwatch kello = Stopwatch.StartNew(); // käynnistä ajastin sortDelegate(num); // kutsu järjestysalgoritmiä return(kello.Elapsed); // palauta aika }
private void TestSortMethod(SortDelegate<int> sort, bool isAscending) { var list = GetTestList(); sort(list, isAscending); output.WriteLine(string.Join(",", list)); Assert.True(list.IsSorted(isAscending)); }
/// <summary> /// Initializes a new instance of the <see cref="SortLogic"/> class. /// </summary> /// <param name="direction">The direction.</param> /// <param name="column">The column.</param> public SortLogic(ListSortDirection direction, DataGridColumn column) { var dir = (direction == ListSortDirection.Ascending) ? 1 : -1; switch ((string)column.Header) {//TODO: сделать нормальную сортировку case "Имя": _compare = (x, y) => CompareToName(x, y, dir); break; case "Тип": _compare = (x, y) => CompareToType(x, y, dir); break; case "Размер": _compare = (x, y) => CompareToLength(x, y, dir); break; case "Дата": _compare = (x, y) => CompareToDate(x, y, dir); break; default: _compare = (x, y) => x.CompareTo(y); break; } }
public ActionResult SearchusingCriteria(SearchInput input) { List <Post> Result = new List <Post>(); using (BlogContext context = new BlogContext()) { if (input != null) { if (input.TitleName != null) { List <Post> Posts1 = context.Posts.Where(p => p.Title.Contains(input.TitleName)).ToList(); Result.AddRange(Posts1); } if (input.TagName != null) { List <Tag> tags = context.Tags.Where(t => t.Tag_Name == input.TagName).ToList(); List <Post> Posts2 = new List <Post>(); foreach (Tag t in tags) { Posts2.AddRange(t.Posts); } Posts2.AddRange(Result); Result = Posts2.Distinct().ToList(); } } } SortDelegate sortOption = NotSort; switch (input.SortingType) { case SortType.DateA: sortOption = DateA; break; case SortType.DateD: sortOption = DateD; break; case SortType.NameA: sortOption = NameA; break; case SortType.NameD: sortOption = NameD; break; case SortType.RateA: sortOption = RateA; break; case SortType.RateD: sortOption = RateD; break; } return(View("~/Views/Post/ViewAllPostsMenu.cshtml", sortOption(Result))); }
public static void TestRecoveryBlockSort() { String[] testStrings = { "the quick brown fox jumps over the lazy dog", "Hello there. I am going to sort this string, but there are some problems.", "#Testing «ταБЬℓσ»: 1<2 & 4+1>3, now 20% off! E-mail @ (me)" }; ObservableCollection <Delegate> sorters = new ObservableCollection <Delegate>(); //Three different ways of building the delegates sorters.Add((Func <String, String>)Sort.MikkelSort); SortDelegate madsSort = Sort.MadsSort; sorters.Add(madsSort); MethodInfo sortMethod = typeof(Sort).GetMethod("MarcSort"); Delegate marcSort = Delegate.CreateDelegate(typeof(SortDelegate), sortMethod); sorters.Add(marcSort); //Print stuff without recovery blocks Console.WriteLine("Unsorted:"); foreach (string unsortedString in testStrings) { Console.WriteLine(unsortedString); } foreach (Delegate sorter in sorters) { Console.WriteLine(sorter.Method.Name + ":"); foreach (string unsortedString in testStrings) { Console.WriteLine(sorter.DynamicInvoke(unsortedString)); } } //Recovery block testing RecoveryBlock sortReco = new RecoveryBlock(sorters, null); sortReco.acceptanceTest = (Func <string, string, bool>)String.Equals; sortReco.acceptanceParameters = new List <Object>(); sortReco.useResultForTest = true; char[] charArr = testStrings[0].ToCharArray(); Array.Sort <char>(charArr); sortReco.acceptanceParameters.Add(new String(charArr)); Console.WriteLine(sortReco.Run <string, string>(testStrings[0])); sortReco.acceptanceParameters.Clear(); sortReco.acceptanceParameters.Add("am are but going Hello I problems. some sort string, there there. this to"); Console.WriteLine(sortReco.Run <string, string>(testStrings[1])); sortReco.acceptanceParameters.Clear(); sortReco.acceptanceParameters.Add(" !#%&()+,-0112234:<>@ETaeeffgiilmmnnoostw«»αστБЬℓ"); Console.WriteLine(sortReco.Run <string, string>(testStrings[2])); }
public void StartSort(string namesort) { SortDelegate sortDelegate = AlphabetSort; var massive = CreateMassive(); Console.WriteLine("Start sorting"); PrintMassive(MySort(massive, sortDelegate)); SortFinish(namesort); }
SortDelegate GetSortFunc(ENSortType type) { SortDelegate func = null; if (m_sortDelegates.TryGetValue((int)type, out func)) { return(func); } return(null); }
public SpanSortPerf( InitDelegate init, SortDelegate sort, int length, int loopsPerRun) { _init = init; _sort = sort; _keys = new int[length]; _loopsPerRun = loopsPerRun; }
public static void StartSortInThread(string[] arr) { SortDelegate del = new SortDelegate(Sorting); del?.Invoke(arr); Thread t = new Thread(delegate() { Sorting(arr); }); t.Start(); Thread.Sleep(500); }
//protected void btnClick_Click(object sender, EventArgs e) //{ // using(var db = new ProductDb()) // { // var prod = db.Products.ToList(); // foreach (Product p in prod) // { // products.Add(p); // } // } //} protected void btnSort_Click(object sender, EventArgs e) { var prod = dropDownSort.SelectedValue; SortDelegate srtdel = new SortDelegate(SortProducts); Sort += srtdel; if (Sort != null) { Sort(prod); } }
void TinySortStep(SortDelegate <char> characterArraySorter) { var copy = new char[11]; Array.Copy(tiny, copy, 11); characterArraySorter(copy); Assert.NotNull(copy); // characterArraySorter.Method.DeclaringType.Name Assert.Equal(inty, copy); }
public static void Sort(List <int> list, SortDelegate del) { for (int i = 1; i < list.Count; i++) { for (int j = 0; j < list.Count - i; j++) { if (del.Invoke(list[j], list[j + 1]) > 0) { int temp = list[j]; list[j] = list[j + 1]; list[j + 1] = temp; } } } }
public static void TimeCheck(int[] array, SortDelegate sort, string name) { Stopwatch timer = new Stopwatch(); timer.Start(); sort(array); timer.Stop(); Console.WriteLine($"Массив после сортировки {name}:"); foreach (int e in array) { Console.Write(e + ","); } Console.WriteLine(); Console.WriteLine("Время работы алгоритма: " + timer.ElapsedMilliseconds); }
// Nem jó, mert két T-t nem tudunk összehasonlítani, hiszen nem tudjuk milyen típus /*static void SortArrayWrong<T>(T[] array) * { * for (int i = 0; i < array.Length - 1; i++) * { * for (int j = i + 1; j < array.Length; j++) * { * if (array[j] < array[i]) * { * var temp = array[i]; * array[i] = array[j]; * array[j] = temp; * } * } * } * }*/ static void SortArray <T>(T[] array, SortDelegate <T> sortDelegate) { for (int i = 0; i < array.Length - 1; i++) { for (int j = i + 1; j < array.Length; j++) { if (sortDelegate(array[i], array[j])) { var temp = array[i]; array[i] = array[j]; array[j] = temp; } } } }
//Metod to use Sorted ASC Table static void MetodiSortedDES(SortDelegate del) { // luo taulukko (satunnaisluvuilla) int[] num = CreateDescendingTable(10000); // //int[] num = new int[100]; //int[] taulukko = CreateTable(10000); // ota aika Stopwatch kello = Stopwatch.StartNew(); del(num); // laske aikaero var elapsedTime = kello.Elapsed; // tulosta Console.WriteLine("Sorting time: {0}", elapsedTime.TotalMilliseconds); }
public double GetSortingTime(SortDelegate sortDelegate, long[] array) { double result; Stopwatch stopwatch = new Stopwatch(); for (int i = 0; i < iterations; i++) { long[] tempArray = new long[array.Length]; Array.Copy(array, tempArray, array.Length); stopwatch.Start(); sortDelegate.Invoke(tempArray); stopwatch.Stop(); } result = stopwatch.Elapsed.TotalMilliseconds / Iterations; return(result); }
string[] MySort(string[] mass, SortDelegate sortDelegate) { string temp; for (int i = 0; i < mass.Length; i++) { for (int j = 0; j < mass.Length; j++) { if (!sortDelegate(mass[i], mass[j])) { temp = mass[i]; mass[i] = mass[j]; mass[j] = temp; } } } return(mass); }
public void SortCards(ENSortType sortType, bool reverse, ENSortClassType classType) { if (sortType == ENSortType.enDefault) { sortType = ENSortType.enGotTime; } SortDelegate sortFunc = GetSortFunc((ENSortType)sortType); if (sortFunc != null) { m_lastSortType = sortType; m_lastDirReverse = reverse; m_sortedCardList = sortFunc(sortType, reverse); CardBag.Singleton.NotifySortResult(); } //SetVisable(false); }
static void Main(string[] args) { SortDelegate selectionSort = new SortDelegate(SelectionSort); SortDelegate insertionSort = new SortDelegate(InsertionSort); SortDelegate quickSort = new SortDelegate(QuickSortMain); SortDelegate arraySort = new SortDelegate(ArraySort); SortDelegate mergeSort = new SortDelegate(MergeSortMain); Console.WriteLine("SelectionSort"); TeeMittaukset(selectionSort); Console.WriteLine("\nInsertionSort"); TeeMittaukset(insertionSort); Console.WriteLine("\nQuicksort"); TeeMittaukset(quickSort); Console.WriteLine("\narraySort"); TeeMittaukset(arraySort); Console.WriteLine("\nmergeSort"); TeeMittaukset(mergeSort); }
static void Main(string[] args) { SortDelegate insertionSort = new SortDelegate(InsertionSort); SortDelegate selectionSort = new SortDelegate(SelectionSort); SortDelegate bubbleSort = new SortDelegate(BubbleSort); SortDelegate quickSort = new SortDelegate(QuickSortMain); SortDelegate shellSort = new SortDelegate(ShellSort); SortDelegate mergeSort = new SortDelegate(MergeSortMain); Metodi(insertionSort); Metodi(selectionSort); Metodi(bubbleSort); Metodi(Array.Sort); Metodi(quickSort); Metodi(shellSort); Metodi(mergeSort); Console.ReadLine(); }
/// <summary> /// Initializes a new instance of the <see cref="SortLogic"/> class. /// </summary> /// <param name="direction">The direction.</param> /// <param name="column">The column.</param> public SortLogic(ListSortDirection direction, DataGridColumn column) { var dir = (direction == ListSortDirection.Ascending) ? 1 : -1; switch ((string)column.Header) {//TODO: сделать нормальную сортировку case "Имя": _compare = (x, y) => CompareToName(x,y,dir); break; case "Тип": _compare = (x, y) => CompareToType(x, y, dir); break; case "Размер": _compare = (x, y) => CompareToLength(x, y, dir); break; case "Дата": _compare = (x, y) => CompareToDate(x, y, dir); break; default:_compare = (x, y) => x.CompareTo(y); break; } }
public void TinySort() { var characterArraySorters = new SortDelegate <char>[] { BinaryInsertion <char> .Sort, Heap <char> .Sort, Insertion <char> .Sort, InsertionX <char> .Sort, Merge <char> .Sort, MergeBU <char> .Sort, MergeX <char> .Sort, Quick <char> .Sort, Quick3Way <char> .Sort, QuickX <char> .Sort, Shell <char> .Sort, }; foreach (var sorter in characterArraySorters) { TinySortStep(sorter); } }
public SortLogic(ListSortDirection direction, DataGridColumn column) { int dir = (direction == ListSortDirection.Ascending) ? 1 : -1; switch ((string)column.Header) { case "ФИО": _compare = (x, y) => x.FIO.CompareTo(y.FIO) * dir; break; case "Права": _compare = (x, y) => x.Permission.ID.CompareTo(y.Permission.ID) * dir; break; case "Стаж": _compare = (x, y) => (x.Commencement ?? DateTime.MinValue).CompareTo(y.Commencement ?? DateTime.MinValue) * dir; break; case "Должность": _compare = (x, y) => x.Appointment.CompareTo(y.Appointment) * dir; break; case "Зарплата": _compare = (x, y) => (x.Remuneration ?? 0).CompareTo(y.Remuneration ?? 0) * dir; break; case "Вкл.": _compare = (x, y) => (x.Enabled ?? false).CompareTo(y.Enabled ?? false) * dir; break; case "": _compare = (x, y) => (x.IsNotSaved).CompareTo(y.IsNotSaved) * dir; break; default: _compare = (x, y) => x.FIO.CompareTo(y.FIO) * dir; break; } }
static void Metodi(SortDelegate del) { int[] taulukko = CreateTable(10000); int[] nousevaTaulukko = CreateAscendingTable(10000); int[] laskevaTaulukko = CreateDescendingTable(10000); Stopwatch kello = Stopwatch.StartNew(); del(taulukko); var elapsedTime = kello.Elapsed; Console.WriteLine(del.Method.Name.ToString() + " Satunnaistaulukko: " + elapsedTime); kello = Stopwatch.StartNew(); del(nousevaTaulukko); elapsedTime = kello.Elapsed; Console.WriteLine(del.Method.Name.ToString() + " Nousevataulukko: " + elapsedTime); kello = Stopwatch.StartNew(); del(laskevaTaulukko); elapsedTime = kello.Elapsed; Console.WriteLine(del.Method.Name.ToString() + " Laskevataulukko: " + elapsedTime); }
public void Sort(SortDelegate d) { List <EquipmentManager.Equipment> list = new List <EquipmentManager.Equipment>(); foreach (var item in equipmentDic) { item.Value.CompareItem = d(item.Value); list.Add(item.Value); } list.Sort(); equipmentDic = new Dictionary <int, EquipmentManager.Equipment>(); int i = 0; foreach (var item in list) { equipmentDic.Add(i++, item); } SetNextItemIndex(); SetEquipments(); }
private void Sort(SortDelegate sd) { Pustaka = new ObservableCollection <Buku>(sd(Pustaka)); }
public static List <IGBWinners> SortListWithDelegate(List <IGBWinners> list, SortDelegate delle) { return(delle(list)); }
private List <EquipmentTemp.Row.Row2> SortFunc(List <EquipmentTemp.Row.Row2> data, SortDelegate sort) { for (int i = 0; i < data.Count; i++) { for (int j = i; j < data.Count - 1; j++) { if (sort(data[i], data[j + 1])) { EquipmentTemp.Row.Row2 temp = data[i]; data[i] = data[j + 1]; data[j + 1] = temp; } } } return(data); }
void RegisterSortFunc(ENSortType sortType, SortDelegate degelate) { m_sortDelegates.Add((int)sortType, degelate); }