chris combe

chris combe

  • 1.6k
  • 22
  • 1.7k

Is Array.Sort() able to sort this (and save the indexes)?

Dec 20 2019 9:59 AM
Hi, I have a double 2D array:

 a[0,0]=1.1 a[0,1]=0.1 a[0,2]=2.9 a[0,3]=1.6
 a[1,0]=-2.2  a[1,1]=-1.7 a[1,2]=0.3 a[1,3]=-0.4
 a[2,0]=2.0 a[2,1]=-0.1 a[2,2]=-1.8 a[2,3]=-3.1
   
 1) I want to sort it in descending order AND save the 2 indexes (in order to know which array indexes has the absolute higher/lower values):

a[2,3]=-3.1
a[0,2]=2.9
a[1,0]=-2.2
a[2,0]=2.0
a[2,2]=-1.8
a[1,1]=-1.7
a[0,3]=1.6
a[0,0]=1.1
a[1,3]=-0.4
a[1,2]=0.3
a[0,1]=0.1
a[2,1]=-0.1

2) I also need another sort: on the first index and save the 2nd index:

a[0,2]=2.9
a[0,3]=1.6
a[0,0]=1.1
a[0,1]=0.1

a[1,0]=-2.2
a[1,1]=-1.7
a[1,3]=-0.4
a[1,2]=0.3

a[2,3]=-3.1
a[2,0]=2.0
a[2,2]=-1.8
a[2,1]=-0.1

Is it possible with "Array.Sort()" ? As a beginner, help will be greatly appreciated!

Thank you very much!

Answers (1)