My current reverse() for my doubly-linked list looks like this:
At first glance it seems fine, but after a bit of testing I ran into this particularity:Code:template <typename T> void
List<T>::reverse(){
if(!empty()){
for(List<int>::Iterator i = begin(); i != end(); i++){
push_front(*i);
}
for(int j = 0; j < size(); j++){
pop_back();
}
}
}
It doesn't swap the head and tail pointers. This causes a bit of confusion when you look-up a value or return a specific position.
So SHOULD I swap head and tail or not?
(head ^ tail) v (!head ^ !tail) << my awful discrete math class...