I have some vector of elements passed to a function and I want to create all of the vectors that are that original vector, but with one element missing.
What is the simplest way to do this in C++?
My current approach is something of the following, but not quite worked out yet.
void list_one_removed(std::vector<Fruit> fruit)
{
for (unsigned i = fruit.size(); i > 0; i--)
{
// copy 'fruit'
// remove index i
// add this vector to some vector of vectors.
}
}
Well, just use an iterator to identify the currently removed position and create a vector from everything up to this iterator and everything after this iterator: