Revised for linked list
Modified for LinkedList