This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin for Android App Development and have Peter Sommerhoff on-line!
See this thread for details.
Win a copy of Kotlin for Android App Development this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Sorting question.  RSS feed

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

There is a simple way to sort in java using Arrays.sort. However, is there anyway i can get an array of indexes which tells me whats the old position of that sorted element? For people who have used Matlab ( [sortval sortpos] = sort(z,'ascend') ), its the sortpos matrix.

for example:-
z = [ 1 10 2 5 4 ]
When you sort you get:-
z_sorted = [ 1 2 4 5 10 ]
I also need an array like this:-
indexs = [ 1 3 5 4 2 ]

I know i can do some post processing on the sorted array to get this, however i was wondering if there is some inbuilt way in java (or some really quick way) of doing this.

Thanks in advance'
Neville
 
Sheriff
Posts: 21612
101
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This exact same question has come up last week or so: http://www.coderanch.com/t/451158/Java-General-beginner/java/Helping-Sorting-Array-Doubles-But
 
He baked a muffin that stole my car! And this tiny ad:
Programmatically Create PDF Using Free Spire.PDF with Java
https://coderanch.com/wiki/703735/Programmatically-Create-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!