toList<T> static method
Converts a linked list to a list of values
head - The head of the linked list
Returns a list containing all values in the linked list
Implementation
static List<T> toList<T>(LinkedListNode<T>? head) {
List<T> result = [];
LinkedListNode<T>? current = head;
while (current != null) {
result.add(current.value);
current = current.next;
}
return result;
}