public void Demo1() { var x = new[] { 3, 2, 1 }; var y = new[] { 3.0, 2.0, 1.0 }; var z = new[] { 6.0, 7.0, 8.0 }; const int From = 0; int to = x.Length; GenericSorting.QuickSort( From, to, (a, b) => x[a] == x[b] ? 0 : (x[a] < x[b] ? -1 : 1), (a, b) => { int t1 = x[a]; x[a] = x[b]; x[b] = t1; double t2 = y[a]; y[a] = y[b]; y[b] = t2; double t3 = z[a]; z[a] = z[b]; z[b] = t3; }); Assert.AreEqual(1, x[0]); Assert.AreEqual(2, x[1]); Assert.AreEqual(3, x[2]); Assert.AreEqual(1.0, y[0]); Assert.AreEqual(2.0, y[1]); Assert.AreEqual(3.0, y[2]); Assert.AreEqual(8.0, z[0]); Assert.AreEqual(7.0, z[1]); Assert.AreEqual(6.0, z[2]); }
public void Demo2() { var x = new[] { 6, 7, 8, 9 }; var y = new[] { 3.0, 2.0, 1.0, 3.0 }; var z = new[] { 5.0, 4.0, 4.0, 1.0 }; const int From = 0; int to = x.Length; GenericSorting.QuickSort( From, to, (a, b) => { if (y[a] == y[b]) { return(z[a] == z[b] ? 0 : (z[a] < z[b] ? -1 : 1)); } return(y[a] < y[b] ? -1 : 1); }, (a, b) => { int t1 = x[a]; x[a] = x[b]; x[b] = t1; double t2 = y[a]; y[a] = y[b]; y[b] = t2; double t3 = z[a]; z[a] = z[b]; z[b] = t3; }); Assert.AreEqual(8, x[0]); Assert.AreEqual(7, x[1]); Assert.AreEqual(9, x[2]); Assert.AreEqual(6, x[3]); Assert.AreEqual(1.0, y[0]); Assert.AreEqual(2.0, y[1]); Assert.AreEqual(3.0, y[2]); Assert.AreEqual(3.0, y[3]); Assert.AreEqual(4.0, z[0]); Assert.AreEqual(4.0, z[1]); Assert.AreEqual(1.0, z[2]); Assert.AreEqual(5.0, z[3]); }
protected void RunSort(int fromIndex, int toIndex, IntComparator c, Swapper swapper) { GenericSorting.QuickSort(fromIndex, toIndex, c, swapper); }