Achieve Internet Interview Question
Country: India
You mean you have a circular linked list and want to emulate behavior of doubly-linked?
push, pop and traverse would work the same way except that instead of checking for node->next == NULL (to find the tail) you'd check for node->next == head.
To traverse backwards, go forward a full circle until you hit newnode->next = node.
Alternatively, maintain 2 circular lists, with same payloads, one for the forward links and one for the back links.
instead of the next pointer of the last node in a double linked list pointing to NULL and the prev pointer of the head node pointing to NULL, change it this way :-
- TheMitraBoy April 21, 2012next pointer of the last node should point to head
prev pointer of the head node should point to the last node
That should do it i guess