// assume ListNode is a valid type
// and head/tail are initialized properly somewhere and filled with data
ListNode *head;
ListNode *tail;
void reverse(ListNode&* start, ListNode&* end){
ListNode *c = start;
while(c && c != end->next){
std::swap(c->next, c->prev);
c = c->prev;
}
// some extra logic goes here, i'm not sure what
}
// reverse(head, tail), reverse(head->next->next, tail->prev) should all be
// valid function calls on the dll
I can never seem to figure out what that extra bit of logic is to correctly update the references and pointers from other nodes.
std::swap(startPoint->next, endPoint->prev);
std::swap(startPoint, endPoint); does not seem to be enough to correct the pointers.