How could this doubly linked list search code be implemented