Message 1 of 6
AcArray sort

Not applicable
06-22-2007
11:51 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I want to sort some items in a AcArray but it isn't working as expected.
[code]
std::sort(&data.first(), &data.last(), SortFileData);
bool SorFileData(const PlotItem& item1, const PlotItem& item2)
{
double x1 = min(item1._start.x, item1._end.x);
double x2 = min(item2._start.x, item2._end.x);
return x1 < x2;
}
[/code]
After calling std::sort, the elements are different then without calling sort, but it is still incorrect.
Results:
"T",169.000,11.438,169.000,14.438,"BO"
"P",240.000,42.000,217.000,42.000,""
"T",217.000,11.438,217.000,14.438,"BO"
"P",240.000,6.000,240.000,42.000,""
"T",25.000,11.438,25.000,14.438,"BO"
As you can see, the last element has a starting point of 25. This should not be the last element.
Any suggestions ?
Mike B
[code]
std::sort(&data.first(), &data.last(), SortFileData);
bool SorFileData(const PlotItem& item1, const PlotItem& item2)
{
double x1 = min(item1._start.x, item1._end.x);
double x2 = min(item2._start.x, item2._end.x);
return x1 < x2;
}
[/code]
After calling std::sort, the elements are different then without calling sort, but it is still incorrect.
Results:
"T",169.000,11.438,169.000,14.438,"BO"
"P",240.000,42.000,217.000,42.000,""
"T",217.000,11.438,217.000,14.438,"BO"
"P",240.000,6.000,240.000,42.000,""
"T",25.000,11.438,25.000,14.438,"BO"
As you can see, the last element has a starting point of 25. This should not be the last element.
Any suggestions ?
Mike B