Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


#ActualiMalc

Posted 06 April 2013 - 04:53 PM

To clarify, it's not a special sorting algorithm you want, virtually all of them can do this. std::sort or std::stable_sort are fine for this.

What you want is special comparison and exchanging functionality. Even then, this sort of thing is not that uncommon.
In order to have it run-time configurable, you may be best to declare a comparator that takes a list of column IDs in its constructor, and whose () operator uses that accordingly. If you don't need to change the order the columns are sorted by at run-time then its even easier, and a very common thing to do.
Then it's just a matter of ensuring it swaps 'rows' correctly, probably via writing a custom swap function for your 'row' class.

#3iMalc

Posted 06 April 2013 - 04:52 PM

To clarify, it's not a special sorting algorithm you want, virtually all of them can do this. std::sort or std::stable_sort are fine for this.

What you want is special comparison and exchanging functionality. Even then, this sort of thing is not that uncommon.
In order to have it run-time configurable, you may be best to declare a comparator that takes a list of column IDs in its constructor, and whose () operator uses that accordingly. If you don't need to change the corder the columns are sorted by at run-time then its even easier, and a very common thing to do.
Then it's just a matter of ensuring it swaps 'rows' correctly, probably via writing a custom swap function for your 'row' class.

#2iMalc

Posted 06 April 2013 - 04:51 PM

To clarify, it's not a special sorting algorithm you want, virtually all of them can do this. std::sort or std::stable_sort are fine for this.

What you want is special comparison and exchanging functionality. Even then, this sort of thing is not that uncommon.
In order to have it run-time configurable, you may be best to declare a comparator that takes a list of column IDs in its constructor, and whose () operator uses that accordingly.
Then it's just a matter of ensuring it swaps 'rows' correctly, probably via writing a custom swap function for your 'row' class.

#1iMalc

Posted 06 April 2013 - 04:50 PM

To clarify, it's not a special sorting algorithm you want, virtually all of them can do this. std::sort or std::stable_sort are fine for this.

What you want is special comparison and exchanging functionality. Even then, this sort of thing is not that uncommon. In order to have it run-time configurable, you may be best to declare a comparator that takes a list of column IDs in its constructor, and whose () operator uses that accordingly.
Then it's just a matter of ensuring it swaps 'rows' correctly, probably via writing a custom swap function for your 'row' class.

PARTNERS