Say I have a list:
list<int> A { 1, 2, 3, 4};
and I do this:
A.remove(5);
What would be returned by this? When I create a simple program for this in Visual Studio, it runs without giving any errors, so I am assuming it is a legal statement.
However, what if I wanted to keep track of whether or not the element is removed, and print out that it has either been removed or the element does not exist?
For example, is there something like this:
if (A.remove(5) == true) {
cout << "Element has been removed" << endl;
} else {
cout << "Element does not exist" << endl;
}
that can be done without looping through the list and comparing 5 to every element if it exists before first calling the remove() function?