added function to check the loop in the linked list