New method to count the number of nodes in the list