public int Compare(IndexValue x, IndexValue y) { if (x.Type == y.Type) { switch (x.Type) { case IndexValueType.Null: return(0); case IndexValueType.DateTime: return(DateTimeComparer.Compare((DateTime)x.Value, (DateTime)y.Value)); case IndexValueType.Integer: return(IntegerComparer.Compare((Int32)x.Value, (Int32)y.Value)); case IndexValueType.Number: return(NumberComparer.Compare((double)x.Value, (double)y.Value)); case IndexValueType.String: return(StringComparer.Compare((string)x.Value, (string)y.Value)); case IndexValueType.Bool: return(BoolComparer.Compare((bool)x.Value, (bool)y.Value)); default: Verify.Argument(true, "Attempt to compare illegal values, {0} and {1}", x.Value, y.Value); throw null; } } return(Comparer <int> .Default.Compare((int)x.Type, (int)y.Type)); }
public void QuickSortWithComparer() { int[] array = new int[] { 43, 23, 80, 15, 789, 27, 90, 69, 66, 158, 45, 32, 1, 22, 77, 66, 44 }; int[] qSortArray = new int[array.Length]; int[] normalSortArray = new int[array.Length]; array.CopyTo(qSortArray, 0); array.CopyTo(normalSortArray, 0); IComparer <int> comparer = new IntegerComparer(); qSortArray.QuickSort(comparer); Array.Sort(normalSortArray, comparer); CompareList(qSortArray, normalSortArray); }
public void Init() { comparer = new IntegerComparer(number); }