Apr 21, 2013 at 6:59am UTC
I'm confused with this one particular while statement. Can someone explain when will the loop be terminated and if possible, some example?
1 2
found = false ;
while (current != NULL && !found)
and also, I'm confused which statement is included in the while loop. Here is the full code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
void list::insert(const int & newItem)
{
nodeType *current;
nodeType *trailCurrent;
nodeType *newNode;
bool found;
newNode = new nodeType;
newNode->info = newItem;
newNode->link = NULL;
if (first == NULL)
{
first = newNode;
last = newNode;
count++;
}
else
{
current = first;
found = false ;
while (current != NULL && !found)
if (current->info >= newItem)
found = true ;
else
{
trailCurrent = current;
current = current->link;
}
if (current == first)
{
newNode->link = first;
first = newNode;
count++;
}
else
{
trailCurrent->link = newNode;
newNode->link = current;
if (current == NULL)
last = newNode;
count++;
}
}
}
Last edited on Apr 21, 2013 at 7:12am UTC
Apr 21, 2013 at 7:06am UTC
There can be said nothing. The loop as can be terminated and can be not terminated. You did not show the compound statement of the loop.
Apr 21, 2013 at 7:37am UTC
Oh ok, I get it now. Thanks for the help!
Last edited on Apr 21, 2013 at 7:59am UTC