Binary Search Tree Set

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ganon11
    Recognized Expert Specialist
    • Oct 2006
    • 3651

    #31
    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.

    Comment

    • Savage
      Recognized Expert Top Contributor
      • Feb 2007
      • 1759

      #32
      Originally posted by Ganon11
      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.
      It works:(!!)

      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.

      Savage

      Comment

      • Savage
        Recognized Expert Top Contributor
        • Feb 2007
        • 1759

        #33
        Does it work now?

        Savage

        Comment

        • Ganon11
          Recognized Expert Specialist
          • Oct 2006
          • 3651

          #34
          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

          • Savage
            Recognized Expert Top Contributor
            • Feb 2007
            • 1759

            #35
            Originally posted by Ganon11
            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.
            I don't understand,this should work.

            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

            Savage

            Comment

            • Ganon11
              Recognized Expert Specialist
              • Oct 2006
              • 3651

              #36
              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

              • Savage
                Recognized Expert Top Contributor
                • Feb 2007
                • 1759

                #37
                Originally posted by Ganon11
                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...)
                I'm just looking to blame something for this slight failure. :D

                Savage

                Comment

                Working...