double linked list algorithm