I have a problem with a sort I am trying to do with a std::vector. I am doing an example below where I push_back some strings like this.
I know I have to use a comparator for this, that I have called: "compare_on_asscending_value"
The problem is that I am not sure of the logic how to write this comparator.
The code below I use inside a buttoncontrol.
I am thinking of to substring the strings so I convert the beginning number into doubles and from here doing a comparator that look if OneNumber > SecondNumber etc...
So my question is how to write this comparator and I beleive I have to write this comparator outside the buttoncontrol ?
Below will show what sort I am after:
This is the sortresult now wich is wrong:
3.55,defg32
20.32,bc4
12.44,ffdasd34
-3.52,c4
-20.45,ab555
-12.44,es48
This is the sort I am after: (Ascending order(Higher->Lower) for the beginning numbers)
20.32,bc4
12.44,ffdasd34
3.55,defg32
-3.52,c4
-12.44,es48
-20.45,ab555
std::vector<string> Sorting;
std::string One = "-20.45,ab555";
std::string Two = "20.32,bc4";
std::string Three = "-3.52,c4";
std::string Four = "3.55,defg32";
std::string Five = "-12.44,es48";
std::string Six = "12.44,ffdasd34";
Sorting.push_back(One);
Sorting.push_back(Two);
Sorting.push_back(Three);
Sorting.push_back(Four);
Sorting.push_back(Five);
Sorting.push_back(Six);
std::sort( Sorting.rbegin(), Sorting.rend()/*, compare_on_asscending_value*/);
String^ ShowSort = "";
for( int i = 0; i < 6; i++ )
{
String^ ShowSort = gcnew String(Sorting[i].c_str());
MessageBox::Show(ShowSort);
}