View Single Post
Old Mar 8th, 2006, 7:52 PM   #1
elford
Programmer
 
elford's Avatar
 
Join Date: Nov 2005
Posts: 35
Rep Power: 0 elford is on a distinguished road
Parameter Mutation

I have a static method (quicksort) that looks to me like it should return a new set of data thats sorted, but should not change the org. data set.

//dataCopy is a float[]
QuickSortStatic.quickSort(dataCopy);
......
public static float[] quickSort(float[] input)
        {
            data = input;
            recQuickSort(0, data.Length - 1); //does the qsort
            return data;
        }

I want to have a line
float[] f = QuickSortStatic.quickSort(dataCopy);
I want f to be an array that is sorted, and dataCopy to be the org., unsorted data. Instead, both f and dataCopy come back as sorted. Somehow dataCopy is being mutated by quicksort. How can I maintain the org. array?
elford is offline   Reply With Quote