I sometimes need to erase an element from a vector using erase function. This works, but do I need to sort the vector later? So there are no gaps in the vector...
I sometimes need to erase an element from a vector using erase function. This works, but do I need to sort the vector later? So there are no gaps in the vector...
Y3K Network http://www.y3knetwork.com
Bringing the software of the future on the net.
I think std::vector's erase method removes that node, so there will be no gap. Also, removing nodes does not affect how the vector has been sorted (for the most part), adding will though.
So no sorts. Anyone else?
Y3K Network http://www.y3knetwork.com
Bringing the software of the future on the net.
There won't be any gaps in the vector.
The whole point in using vectors is because they're self sizing and you can erase elements and insert elements. Of course, that would take you about 3 minutes to test, so I can see why you wouldn't want to be bothered.
for vectors use the erase-remove trick
std:: omitted for brevityCode:vector<int> vec; // load vector with ints. // now lets erase all elements that hold 100 vec.erase(remove(vec.begin(),vec.end(),100),vec.end()); // wanna erase by predicate.... like this.. vec.erase(remove_if(vec.begin(),vec.end(),MyPredicate),vec.end());
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
i am working on a program containing this right now. i think that you have to make a for loop:
for(int i=0; i<array.length; i++)
{
if(array[i]==" ")
{
array[i]==array[i+1];
}
array[max index value]=" ";
}
i think this should work