template<typename T>
void DoublyLinkedList<T>::moveToFront(ListNode<T>* n)
{
if (head == n) // if n is the head just return
{
return;
}
elseif (tail == n)
{
n->prev->next = 0;
tail = n->prev;
}
else // n is in the middle of list
{
n->prev->next = n->next;
}
// make n the head of the list
head->prev = n;
n->next = head;
n->prev = 0;
head = n;
}
I've walked through it a few times, and I feel like this correct. However, my program's output is off and I'm guessing this function is the culprit. I think I just need a different pair of eyes to take a look at it. Again, I am pretty new to this, so I haven't gotten linked lists down exactly. Any insight is greatly appreciated.