asp.net mvc 3 - Sort an array and return index of arrays according to elements size in c# -
i need sort array minimum maximum value, need return index of array after sorting it. dont want swap values, need return values index according value size, eg
int[] arr = {7,8,2,3,1,5}; (int i=0; i<=arr.length; i++) { int index = array.indexof(arr, i); }
now want return index of values minimum maximum 4,2,3,5,0,1.
your check in loop wrong should i < arr.length
. index can do:
int[] arr = { 7, 8, 2, 3, 1, 5 }; int[] sortedindexarray = arr.select((r, i) => new { value = r, index = }) .orderby(t => t.value) .select(p => p.index) .toarray();
for output:
foreach(int item in sortedindexarray) console.writeline(item);
output:
4 2 3 5 0 1
Comments
Post a Comment