Sep 10, 2019 at 10:36am Sep 10, 2019 at 10:36am UTC
1 2 3 4 5
if (first == NULL)
{
first = NULL;
last = NULL;
}
Now that's a weird thing to write.
Probably you meant
1 2 3 4 5
if (first == NULL)
{
first = newNode;
last = newNode;
}
Please:
- correct as above
- remove the line with assert in
- define
nodeType *first, *last;
in your class declaration and NOT in either buildListForward() or print(). (TBH they would be better initialised to NULL (or, better, nullptr) in the class declaration.)
Last edited on Sep 10, 2019 at 10:49am Sep 10, 2019 at 10:49am UTC
Sep 10, 2019 at 11:09am Sep 10, 2019 at 11:09am UTC
Show your
whole revised code. I get
Enter a list of integers ending with -999.
45 67 89 65 -999
45 67 89 65
Make sure that you followed the instruction
define
nodeType *first, *last;
in your class declaration and NOT in either buildListForward() or print()
Last edited on Sep 10, 2019 at 11:11am Sep 10, 2019 at 11:11am UTC
Sep 12, 2019 at 8:15am Sep 12, 2019 at 8:15am UTC
@Bopaki,
Please, READ MY LAST POST!
You redeclare first and last in buildLForward::buildListForward() (see line 20) - DON'T!
You redeclare first in vbuildLForward::print() (see line 47) - DON'T!
These would create completely new variables in those routines that just happen to have the same name as (and hence hide) the originals.
Don't you think it would cause utter confusion if I decided to call myself Bopaki?
Last edited on Sep 12, 2019 at 8:25am Sep 12, 2019 at 8:25am UTC
Sep 12, 2019 at 8:27am Sep 12, 2019 at 8:27am UTC
Thanks lastchance I corrected those errors, and now my program runs fine.