2-D array sort in C# -help

Discussion in 'Programmer's Corner' started by knibknob, May 12, 2010.

  1. knibknob

    Thread Starter New Member

    Apr 22, 2010
    Hello all, I am a beginner to C#, and am currently working on converting a table with x & y values, and I desire to sort the table with the x-values, while keeping the associated y-values. Currently, I am pulling the values from a text file to an array, and then sorting the array, and outputting back to a text file. The I/O parts I have already mostly figured out, but the sorting of the array is proving difficult. I was wondering if it were possible to utilize the .Sort method while keeping the values associated with whats sorted. Also, it would be nice to be able to utilize quick sort. Here is some sample code, but it doesn't seem to work, so I am willing to try any kind of method, but I am hoping I do not need to resort to sorting an identical array and matching it up to the corresponding values. Thanks in advance for the assistance.

    Code ( (Unknown Language)):
    1. int length = tempNumbers.Length;
    2.             double[][] sortData = new double[length][];
    4.             for (int x = 0; x < length; x++)
    5.             {
    6.                 sortData[x] = new double[2];
    7.             }
    8.             Array.Sort<double[]>(sortData, new ArrayComparer());
    10. internal sealed class ArrayComparer : IComparer<double[]>
    11.         {
    12.             #region IComparer<double[]> Members
    13.             public int Compare(double[] x, double[] y)
    14.             {
    15.                 //if (x[0] == null)
    16.                 //    return 0;
    17.                 return x[0].CompareTo(y[0]);
    18.             }
    19.             #endregion
    20.         }
    Nevermind, I simply used a simple quicksort algorithm; how do you delete a thread? o_O
    Last edited: May 12, 2010