Doubly Linked List

reverend boltron

Senior member
Nov 18, 2004
945
0
76
Hey guys, I'm programming a doubly linked list object in c++ and I was wondering if anyone could help me out. This is for school, and I have it done, it just keeps on crashing in the test program. So yeah if I could get some help that'd be great. I can send the object source and test program. I also drew a neat little diagram of the DLL so you guys know what kind I'm building.

Thanks in advance. And I really don't want the answer in code or anything, just like, if you see something, let me know what I should be looking out for.

picture of DLL
 

reverend boltron

Senior member
Nov 18, 2004
945
0
76
Because there are special cases where having the first and last nodes as dummy nodes will make programming the whole list a lot easier. I forget the exact reason why, but that's how the teacher wants them programmed.
 

beggerking

Golden Member
Jan 15, 2006
1,703
0
0
another implementation may be :

firstnode->previous should be address of first node
lastnode->next should be address of lastnode
 

mundane

Diamond Member
Jun 7, 2002
5,603
8
81
Kudos to you on not asking people to fix your code. However, in this case it would probably be worthwhile to post your source at least, it's easier than PMing and email.
 

mundane

Diamond Member
Jun 7, 2002
5,603
8
81
Try using the "Attach Code" button in the message window. It'll preserve your formatting =)
 

beggerking

Golden Member
Jan 15, 2006
1,703
0
0
umm.. lets see..where does it crush? adding a node to ends? inserting a node? reading a node value?

did you accidently read the data on dummy nodes?
 

reverend boltron

Senior member
Nov 18, 2004
945
0
76
Well, right now it's crashing around the deleting area, but before, it was crashing after trying to display it from storing at the end, but I think I fixed that.
 

beggerking

Golden Member
Jan 15, 2006
1,703
0
0
a couple places questionable..

destructor..
while (Last->Next != NULL)
should be last->next->next !=null
 

reverend boltron

Senior member
Nov 18, 2004
945
0
76
Originally posted by: beggerking
a couple places questionable..

destructor..
while (Last->Next != NULL)
should be last->next->next !=null

Good catch! Thanks. I just plugged that in there, and I think you probably saved me another headache. I'm still running into errors with the test program (it's the program that the teacher is using to test our programs) that are occuring before that.

Specifically in the test program when it says
"Deleted 9 13 14. Should now be:
10 12 8 11 7 6 1 2 3 4 5:" .. that's where it crashes.
 

reverend boltron

Senior member
Nov 18, 2004
945
0
76
Originally posted by: IHateMyJob2004
Debug mode?

Yeah, that's definitely something on my list of things to learn how to use. I've never really tried it before, but I'll fire it up now and see what progress I can make in there.
 

beggerking

Golden Member
Jan 15, 2006
1,703
0
0
Originally posted by: reverend boltron

Specifically in the test program when it says
"Deleted 9 13 14. Should now be:
10 12 8 11 7 6 1 2 3 4 5:" .. that's where it crashes.


did it crush? or did it return incorrect results?
if incorrect results, what did it return?
 

reverend boltron

Senior member
Nov 18, 2004
945
0
76
Originally posted by: beggerking
also, do you HAVE to use dummy nodes? ...

I think so. I mean, it's stated in the assignment:

Properties:
First - Node pointer to first dummy node - private
Last - Node pointer to last dummy node - private
Current - Node pointer to the current node - private
 

beggerking

Golden Member
Jan 15, 2006
1,703
0
0
Originally posted by: reverend boltron
It crashes there. When I load up the debugger, it brings me to my EndOfList function.

that means you tapped into a dummy node, so there is no ->next->next link..

 

reverend boltron

Senior member
Nov 18, 2004
945
0
76
Sweet! Thanks, I'll look into that further.

Edit:
Actually, that's weird, because that function should just return a boolean value. :confused:
 

reverend boltron

Senior member
Nov 18, 2004
945
0
76
Originally posted by: beggerking
if(Current != First || Current != Last)
should be if(current!=first and current!=last)

That part of the code is testing to make sure that we're not deleting either the first node or the last node, which is why I put the 'or' in there, wouldn't the current node have to be equal to two different values (the address of the first node pointer and the last node pointer) for that condition to bypass the delete?

Edit: Sorry, I think my head exploded there for a second. So I get it, we're making sure it's NOT equal to those two values. It all makes sense now. But it's still not working.
 

igowerf

Diamond Member
Jun 27, 2000
7,697
1
76
Originally posted by: reverend boltron
Originally posted by: beggerking
if(Current != First || Current != Last)
should be if(current!=first and current!=last)

That part of the code is testing to make sure that we're not deleting either the first node or the last node, which is why I put the 'or' in there, wouldn't the current node have to be equal to two different values (the address of the first node pointer and the last node pointer) for that condition to bypass the delete?

When you're using OR, only one of the conditions needs to be true right? If Current == Last, then the first condition is true and the whole statement resolves to true.

Give this code a try:
 

beggerking

Golden Member
Jan 15, 2006
1,703
0
0
assuming you did all your pointers correctly..
sorry, i'm using notepad here...so the indentation is a mess..