implemented recursive approach for linkedlist q2-2