Re: STL vector iterator question
On 2007-09-04 15:43:07 -0400, "T. Crane" <trevis.crane@gmail.com> said:
The max intensity is found by dereferencing maxInt. However, at this
point I'm at a loss as to how to get the corresponding (x,y,z) values
for that max intensity.
Alternatively, if I were to group the data using method A, once I have
a max intensity, it's trivial to find the (x,y,z) values, but I don't
know a good (i.e. easy, elegant, whatever) way to find the max
intensity short of writing a max_element-like function.
Back in the days of FORTRAN, we used parallel arrays to store data
values because FORTRAN didn't have structured data. In C++ we have
structured data, and parallel arrays are rarely appropriate. Is there a
good reason for using the old-fashioned (<g>) approach?
struct point_intensity
{
double x;
double y;
double z;
double intensity;
};
vector<point_intensity> v;
struct compare_intensity
{
bool operator()(const point_intensity& p1, const point_intensity& p2)
{ return p1.intensity < p2.intensity; }
};
vector<point_intensity>::const_iterator loc = max_element(v.begin(),
v.end(), compare_intensity());
--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)