Sorting Parallel Arrays in Java

后端 未结 5 626
青春惊慌失措
青春惊慌失措 2021-01-21 06:19

I have two arrays, one stores the distance of the cities and the other stores the corresponding population. Everything works fine if the distance of the cities is in ascending o

5条回答
  •  面向向阳花
    2021-01-21 06:53

    A "cheap" way would be to have a third array which would contain 0 to n representing the index of the other arrays

    But the problem you are having would disappear if they were grouped in a class, both information seem logically related. Then you would implement Comparable: https://stackoverflow.com/a/18896422

提交回复
热议问题