Deduplication of a doubly linked list