little logical problem with vector...need little help
Author Message
little logical problem with vector...need little help

I have two vector std::vector<long> position and std::vector<long>
FrameSelectionner;

FrameSelectionner contain the values 0 to 10

for(compteur=0;compteur<Form1->FrameSelectionner.size();compteur++)
{

Form1->position.insert(Form1->position.begin(),Form1->FrameSelectionner[compteur]);

}

the result is 10,9,8,7,6,5,4,3,2,1,0......

I want delete some values in Form1->position the values are entred in
tempdelete.

tempdelete's values= 1,4,5,7,9;

suppose to obtain 10,8,6,3,2,0 !

for(i=0;i<tempdelete.size();i++)
{

Form1->FrameSelectionner.erase(FrameSelectionner.end()-tempdelete[i]+compteur);

// but this line crash... I thinks the the minus the the ( )...
}

I'm able to do this when the order is 0,1,2,3,4,5,6,7,8 but I need the
inverse order... and It's too slow to erase in the order and inverse the
vector after that.

thanks

Tue, 01 May 2001 03:00:00 GMT
little logical problem with vector...need little help
Hi,

Quote:

>I want delete some values in Form1->position the values are entred in
>tempdelete.

>tempdelete's values= 1,4,5,7,9;

>suppose to obtain 10,8,6,3,2,0 !

>for(i=0;i<tempdelete.size();i++)
> {

Form1->FrameSelectionner.erase(FrameSelectionner.end()-tempdelete[i]+compteu
r);

Quote:
>  // but this line crash... I thinks the the minus the the ( )...
> }

The problem is that you modify FrameSelectionner during the process -
after you delete first element, the position of the next is moved.

Quote:
>I'm able to do this when the order is 0,1,2,3,4,5,6,7,8 but I need the
>inverse order... and It's too slow to erase in the order and inverse the
>vector after that.

If you are sure about the order,
reverse deletion sequence:

for(i = tempdelete.size() - 1; i >= 0; i--)
....

Mike.
--

My ICQ# is 3769608 or, http://wwp.mirabilis.com/3769608

Tue, 01 May 2001 03:00:00 GMT

 Page 1 of 1 [ 2 post ]

Relevant Pages