Linked list sort by number

The function I created to sort the list by an ID number is only returning the first line from the text file and then goes into an unexpected error. What am i missing or got backwards. the main portion is not using a class but 2 structs. Here is the function.

nodeType *byID (ifstream& infile, nodeType *list, infoType one)
{
nodeType *start, *end, *fill;
one = getData(infile);
bool found;

fill = new nodeType;
fill->info = one;
fill->link = NULL;

if (list == NULL)
{
list = fill;
return list;
}
else
{
start = list;
found = false;
end = NULL;
while (start != NULL && !found)


if (start->info.id < one.id)
found = true;
else
{
end = start;
start = start->link;
}
if (start == list)
{
fill->link = list;
list = fill;
return list;
}
else
{
end->link = fill;
fill->link = start;
return list;
}
}
}
if you would like to see the main i can post it as well. All other functions i made are working properly its just this one.
I can't see it. Have you tried STEPing thru the code and displaying the values of the VARs ?

What makes me think of checking the values in your code, is this:

found = false
...
while (start != NULL && !found)

well, the && !found will always be true, so why bother checking?

- Stepping through the code and checking the values of each variable
will (read:should) high light (a) at what point the code fails, and (b) why it fumbles after the first line of the text file.

It sounds as though once the first line of code is being found, that a condition is being satisfied and it exits rather than checking for more.

Again, stepping through the code will reveal this.

Last edited on
Thanks for some insight, I haven't really tried to go back and step through it since the initial creation. I will and let you know what I find out it might be a day or two before I can get back to the problem.
Topic archived. No new replies allowed.