/// <summary> /// Sorts jagged array by sum of every row /// </summary> /// <param name="array">input array</param> /// <param name="Comparator">delegate that contain compare method</param> /// <param name="ascending">true if sort ascending</param> /// <exception cref="ArgumentNullException">if input parameter is null reference</exception> /// <exception cref="ArgumentException">if input array or Comparator is empty</exception> public static void BubbleSortWithComparator(int[][] array, MyComparator Comparator, bool ascending) { if (array == null || Comparator == null) { throw new ArgumentNullException(); } if (array.Length == 0) { throw new ArgumentException(); } for (int j = 0; j < array.Length - 1; j++) { for (int i = 0; i < array.Length - 1; i++) { if ((ascending && (Comparator.Invoke(array[i], array[i + 1]) > 0)) || (!ascending && (Comparator.Invoke(array[i], array[i + 1]) < 0))) { int[] buf = array[i + 1]; array[i + 1] = array[i]; array[i] = buf; } } } }
public void testGenericJavaImplementation1_1() { IComparator <IMap <string, object> > sDisplayNameComparator = new MyComparator(); IList <IMap <string, object> > myData = new ArrayList <IMap <string, object> >(); myData.Add(new HashMap <string, object>()); myData.Add(new HashMap <string, object>()); Java.Util.Collections.Sort(myData, sDisplayNameComparator); AssertNotNull(myData); }
public static void UniversalSort(ArrayList _items, MyComparator _comparator) { bool sorted = false; do { sorted = true; for (int i = 0; i < _items.Count - 1; i++) { if (_comparator(_items[i], _items[i + 1]) > 0) { object tmp = _items[i]; _items[i] = _items[i + 1]; _items[i + 1] = tmp; sorted = false; } } } while (!sorted); }