Comapring and sorting two separate vectors

Sorting related information in two separate vectors

Page 1 of 1

3 Replies - 725 Views - Last Post: 26 March 2010 - 05:20 AM Rate Topic: -----

#1 ABOU  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 09-December 08

Comapring and sorting two separate vectors

Posted 25 March 2010 - 11:17 AM

I am developing a program which sorts images according to a percentage value which is calculated and stored in a vector of floats.
The corresponding file name is held in a similar vector of Files.

Currently due to the order that the files are processed the vector element indexes correspond to each other.

I have looked at using the java.util.Collections; class to sort the vector of floats but by performing this action the vector of Files will have indexes that no longer correspond to the vector of floats.

Is there a way to sort the float array and arrange the File array to correspond to the new assigned indexes of the float array?

Is This A Good Question/Topic? 0
  • +

Replies To: Comapring and sorting two separate vectors

#2 NeoTifa  Icon User is offline

  • NeoTifa Codebreaker, the Scourge of Devtester
  • member icon





Reputation: 4202
  • View blog
  • Posts: 18,438
  • Joined: 24-September 08

Re: Comapring and sorting two separate vectors

Posted 25 March 2010 - 11:43 AM

Well, it depends on how you're going to sort them. From what I can see, you're probably going to have to do it all manually. But then again I'm a n00b. And I'm curious as to what the percentages represent...
Was This Post Helpful? 0
  • +
  • -

#3 macosxnerd101  Icon User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12298
  • View blog
  • Posts: 45,399
  • Joined: 27-December 08

Re: Comapring and sorting two separate vectors

Posted 25 March 2010 - 12:13 PM

Better to use a class, and implement the Comparable interface. This way, you encapsulate all corresponding data into one Object. As you're running into, it is very easy to mismatch data when sorting parallel Collections.

You might want to check out my tutorial on Moving Away From Parallel Arrays, which covers class design from a parallel array design.
Was This Post Helpful? 0
  • +
  • -

#4 ABOU  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 09-December 08

Re: Comapring and sorting two separate vectors

Posted 26 March 2010 - 05:20 AM

I think I may have shot myself in the foot a little in my development method. I will take a look at that tutorial hopefully it gives me some pointers. thank you
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1