You need to decide what terminates a list (as it is written). For example, you can write a list of numbers as:
1 2 7 -3 98 5
...in which case the list ends when the input ends.
You could write a list as:
(1 2 7 -3 98 5)
which makes it easier to 1. recognize a list (it starts with an open parenthesis) and 2. recognize the end of the list (it ends with a close parenthesis).
You could embed information about the list:
#list 6 1 2 7 -3 98 5
which again makes it easy to recognize a list, tells information about the list (it has 6 elements), and gives the list following.
Effectively, how you _write_ the list matters a great deal. I personally like s-expressions:
((1 2) (7 -3) (98 5))
this would make it very easy to parse lists of lists... or a list of pairs, etc.
Last thing. You should abort if there is an input error:
1 2 3 4 5 6
|
while (...)
{
if (!(input >> temp_x)) break;
if (!(input >> temp_y)) break;
list.InsertNode( temp_x, temp_y );
}
|
That way improper lists and prematurely-terminated lists won't cause extraneous (and invalid) input to get tacked-on to the end of your list.
Hope this helps.
[edit] jsmith: a newline is whitespace...