我需要一个float[]
待排序。我需要知道旧索引在新数组中的位置。这就是为什么我不能使用Array.Sort();
管他呢。因此,我想编写一个函数来对数组进行排序,并记住它从哪个索引获取每个值:
float[] input = new float[] {1.5, 2, 0, 0.4, -1, 96, -56, 8, -45};
// sort
float[] output; // {-56, -45, -1, 0, 0.4, 1.5, 2, 8, 96};
int[] indices; // {6, 8, 4, 2, 3, 0, 1, 7, 5};
数组的大小约为 500。我应该如何处理这个问题?什么排序算法等
After solved: It always surprises me how powerful C# is. I didn't even though of it being able to do that task on it's own. And since I already heard that
Array.Sort()
is very fast I'll take it.