solution for linked list, finished