for single-way linked lists like this:
head->node1->node2->NULL
tail->node2
Code:
Node* prev = NULL;
Node* ptr = head;
// swap the pointers around
while(ptr->next != NULL)
{
Node* next = ptr->next;
ptr->next = prev;
prev = ptr;
ptr = next;
}
// last node
ptr->next = prev;
// switch the head and tail
ptr = head;
head = tail;
tail = ptr;
for double-way linked lists like this:
0<->node1<->node2<->NULL
head->node1
tail->node2
Code:
Node* ptr = head;
// swap the pointers around
while(ptr->next != NULL)
{
Node* next = ptr->next;
ptr->next = ptr->prev;
ptr->prev = next;
// go through prev because we switched next and prev
ptr = ptr->prev;
}
// last node
ptr->next = ptr->prev;
ptr->prev = NULL
// switch the head and tail
ptr = head;
head = tail;
tail = ptr;
NOTE: this code hasn't been tested/compiled. Should give you an idea though
hope this helps
U.