I study algorithms, and the exercise asked me to convert a linked list to an array (using pseudocode), here is what I did:
convert_LL_array (List, array) i = 0 current = List.start while (current != null) array[i] = current->data current = current->next i++ return array
And here is the answer:
convert_LL_array (List, array) i = 0 current = List.start while (current->next != null) array[i] = current->data current = current->next i++ return array
Why should I use "current-> next" when compared to "null"? I think this does not add the last element to the array.
source share