by Francis Glassborow <francis.glassborow@[EMAIL PROTECTED]
>
May 6, 2008 at 08:40 AM
Gerhard Wolf wrote:
> Hi,
>
> i have to vectors.
> std::vector<double> a;
> std::vector<double> b;
> same type, size and have synchronous value pairs. The values in "a" are
> decimal time values (linear increasing).
You mean they are sorted? If they aren't create a couple of working
copies and sort them.
Now look up std::merge. Note that all sequence algorithms work correctly
as long as you can provide start and one past the end iterators for the
sequence. In this case you need the iterator for the first element of
the (sorted) a and b that is greater than the startvalue and the the
iterators for the first element in each that is greater than the
endvalue. Also note that you will need to know how many elements there
will eventually be in the merged result.
>
> Now i want to copy in a 3rd vector "c" all elements from a start value
> to a end value. My first idea was something like:
>
> std::vector<double> c; // target
> for (std::vector<double>::iterator it=a.begin(); it != a.end(); it++) {
> if (*it > startvalue && *it < endvalue) {
> c.push_back(?);
> }
> }
>
> do i need a 2nd iterator for vector b !? but how?
> or ist there a easier was to get the values to vector c?