created a test method for linked list, which can handle dynamic inputs