I have a problem, for example: "How to find the middle node of one linked list in only one crawl, and the twist is that we do not know the number of nodes in the linked list?"
I have an answer like "take a vector and start pushing all the addresses of the nodes when and when you go through the linked list and increase the counter until you reach the end of the list." Therefore, at the end we can get the number of nodes in the list, and even if (counter / 2) or if odd (counter / 2 + counter% 2) gives the average node number, and with this we can get vectore.at(middlenodenumber) points to middle node. "
That's fine ... but it's a waste of memory storing the entire address of a very large linked list! So how can we find the best solution?
source share