That's what I think, too. If I didn't have that parent link, there wouldn't be a problem with segfault errors. However, in order to implement the incrementation operators in my iterator classes, I need that parent link - it is also dictated in the book. There are other methods of incrementation, but the one I was told to implement was the one with the parent link.
Binary Search Tree Set
Collapse
X
-
It works:(!!)Originally posted by Ganon11That's what I think, too. If I didn't have that parent link, there wouldn't be a problem with segfault errors. However, in order to implement the incrementation operators in my iterator classes, I need that parent link - it is also dictated in the book. There are other methods of incrementation, but the one I was told to implement was the one with the parent link.
in create initialize parent to NULL,in insert I have added these lines:
[CODE="cpp"] if ((*temp)->data < obj)
{
insert(&(*temp)->right, obj);
(*temp)->right->parent=(*temp) ;//<------
}
else if (obj < (*temp)->data)
{
insert(&(*temp)->left, obj);
(*temp)->left->parent=(*temp) ;//<------
}
else{
insert(&(*temp)->left, obj);
(*temp)->left->parent=(*temp) ;//<-----
}
[/CODE]
And it runs without seg on VC.I sure hope it works on your compiler.
SavageComment
-
Unfortunately, no, it doesn't work for me. The homework was due today, so I turned in what I had - partial credit should be better than a 0. I did end up getting most of it working, though, so maybe I'll get a high grade anyway. We'll see.
Thanks SO MUCH for your help, Savage.Comment
-
I don't understand,this should work.Originally posted by Ganon11Unfortunately, no, it doesn't work for me. The homework was due today, so I turned in what I had - partial credit should be better than a 0. I did end up getting most of it working, though, so maybe I'll get a high grade anyway. We'll see.
Thanks SO MUCH for your help, Savage.
Have you tried with other compilers?
Are you sure that it's still the parent variable the one producing a seg?
Perhaps,it's something else..
I hope that you will get a high mark..
It's all STL's standards fault.It's to messy. :D
SavageComment
-
Actually, the STL set uses a different traversal method, so I suspect it's not messy. I haven't tried other compilers...but we're supposed to be using g++, and that's what was throwing errors. Maybe I'll try in Visual C++ (I think my laptop has that...)Comment
-
I'm just looking to blame something for this slight failure. :DOriginally posted by Ganon11Actually, the STL set uses a different traversal method, so I suspect it's not messy. I haven't tried other compilers...but we're supposed to be using g++, and that's what was throwing errors. Maybe I'll try in Visual C++ (I think my laptop has that...)
SavageComment
Comment