c# - sorting array indices by the array values -
I'm trying to write a function that takes this type of [4,7,2,1,9] array , Then another array like this
[4,1,0,2,3] // Sorting index for input array values I have tried this code, but it is not working properly, I want to write a function which organizes this kind of array with minimal cost
public Zero solution (int [] D) {int [] sorted = New Int [d. Lenth]; For (int i = 0; i & lt; d. langti; i ++) {int ind = 0; For (int j = 0; j and lt; d.langath; j ++) {if (d [j]> d [ii]) & amp; {Ind = j; }} Sorted [i] = ind. }}
array. Second array:
var data = new [] {4, 7, 2, 1, 9}; Var index = new [] {0, 1, 2, 3, 4}; Array (data, index); If you want it in descending order, then use Array.Reverse or pass it to a IComparer order swap:
class reverse-slot: iCompair & lt; Int & gt; {Compare public integers (int x, int y) {return y.CompareTo (x); }} Array. Data (data, index, new reverse-sort); Unfortunately the array. Sir does not have a good overload, which takes two arrays + one representative like the other overloads.
Comments
Post a Comment