Results 1 to 1 of 1
Thread: Regarding custom sorting
- 02-16-2010, 08:50 PM #1Member
- Join Date
- Feb 2010
- Rep Power
Regarding custom sorting
I would like to as your help for coding a customized sort method.
I am trying to sort a vector which has strings as its elements. Each of this string has 2 or 3 parts. For example:
unsortedVector contains XXX.ER , XXX.TB, XXX.PQ, XXX.PQ.1, YYY.DC, YYY.GD, YYY.PQ
This is sorted in the alphabetical order as we can see. Lets name the each of the vector elements in parts.
In XXX.PQ.1, XXX is part 1, PQ is part 2 and 1 is part 3.
Now the part 1 of the string element should be sorted alphabetically. But the part 2 of the string should be sorted in the following order: PQ, GD, DC, TB, ER. In case the part 3 exists then the sorting should be done such that the string without the part 3 comes first and the ones without them come after it and sorted in the numeric order.
I am trying to create a base vector with the sequential order of PQ, GD, DC, TB, ER.I have retrieved the 2nd part of string of two consecutive vector elements and checked their indexes in the base vector. In case the 1st element has a higher index than the lower one then we should swap their positions else continue.
I have tried for 2 days now and i am not able to sort them at all.
Could anyone suggest a good code snippet/algorithm for this?
Thanks and Regards,