flattening a nested linked list