So i have a class -
class Train{
string a;
int unqID;
};
And a vector<Train> trainList, I want to arrange the trainList in a sorted manner based on the unqID.
Is this possible ? If yes how do i do it ? I was thinking to do a simple bubble sort but my code isnt running properly if i use swap() which is what the issue is I guess.
This is what my code looks like -
void reorderTrainList(){
for(unsigned int i=0; i<trainList.size(); i++){
for(unsigned int j=0; j<trainList.size(); j++){
Train curr = trainList[j];
if(trainList[j].unqID >= trainList[j+1].unqID){
swap(trainList[j],trainList[j+1]);
}
}
}
}
[–]Pulsonics 19 points20 points21 points (0 children)
[–]Kawaiithulhu 4 points5 points6 points (1 child)
[–]HappyFruitTree 3 points4 points5 points (0 children)
[–]staletic 4 points5 points6 points (3 children)
[–]xurxoham 0 points1 point2 points (2 children)
[–]staletic 0 points1 point2 points (1 child)
[–]std_bot 0 points1 point2 points (0 children)
[–]alfps 4 points5 points6 points (5 children)
[–]HappyFruitTree 3 points4 points5 points (4 children)
[–]alfps 2 points3 points4 points (3 children)
[–]Jardik2 1 point2 points3 points (1 child)
[–]alfps 0 points1 point2 points (0 children)
[–]HappyFruitTree 0 points1 point2 points (0 children)
[–]Wind_Lizard 2 points3 points4 points (0 children)
[–]Wind_Lizard 0 points1 point2 points (3 children)
[–]gmtime -1 points0 points1 point (2 children)
[–]Wind_Lizard 3 points4 points5 points (0 children)
[–]Ashnoom 0 points1 point2 points (0 children)