Re: about new and delete
Sam wrote:
Juha Nieminen writes:
And what is the complexity of removing an element from the middle of t=
he
list, versus the middle of a vector?
O(n) for both.
Hahahahahaha.
std::list<obj> theList;
// =85
std::list<obj>::iterator p;
// =85
theList.erase(p); // Warning, O(n)!!!!!
Very funny.
If you want to prove me wrong, writ=
e a function which
takes a std::list as parameter and removes the element at the exact
middle faster than O(n).
What you fail to grok, is that when you have a member of containe that yo=
u
want removed, you already have its iterator, you don't need to search for
it.
Who said something about "having a member"?
Thank you for playing.
*yawn*
You simply phrased your question badly, Sam. It's not obvious if an
iterator to the middle element is already known. I do think you're
smart enough to grok what was going on. Juha even explained how he
interpreted the question by saying "write a function which takes a
std::list as parameter and removes the element at the exact middle
faster than O(n)". But instead of saying something like
"Yes, O(n) if you don't know the iterator. But I was assuming
that it is known. In that case std::list makes a difference."
you try to make it look like you're the only sane person here.
-1 for weak communication skills.
Cheers,
SG