circular doubly linked list algorithm