Implemented query function for linked list.