0
Counting non-nulls in an Array of linked lists
Say I have an array of length 3 , and each index contains a linked list as below: [LL1 -> next -> next -> null [null [LL2 -> null The first index contains a list which has 2 values, the second index is null, and the third index contains a empty list where the head points to null. Say, I want to count the number of lists in this array. To do that, I thought I should have a counter variable and loop through the array and increment counter for every non-null spot. But I think LL2 would get counted as a null spot. How do I prevent that?
1 ответ