Jump to content
  • Advertisement
Sign in to follow this  
Thirthe

[C++] a tree and diff. g++ versions

This topic is 3887 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello. consider this function for inserting a node into the tree
void add_r(int descendant_, int ancestor_, node *&leaf)
        {

                if(leaf== NULL){
                        leaf= new node;
                        leaf->data= ancestor_;
                        leaf->next= new node*[8];
                        leaf->next[0]= new node;
                        leaf->next[0]->data= descendant_;
                        leaf->size++;
                        depth=0;
                }
                else if(leaf->data != ancestor_){
                        if(leaf->next != NULL){
                        for(int i=0; i < leaf->size; i++)
                                add_r(descendant_, ancestor_, leaf->next);
                        }
                        else cout<<"error2!: "<<endl;
                }
                else if(leaf->data == ancestor_){
                        if(leaf->next == NULL){
                                leaf->next= new node*[8];
                                depth++;
                                cout<<"mofo"<<endl;
                        }

                        leaf->next[leaf->size]= new node;
                        leaf->next[leaf->size]->data= descendant_;
                        leaf->size++;

                }
        }


when i compile this program on a win32 host(g++ 3.4.2 mingw special), the output is nothing, and the depth is 0. but when i compile this program on a freebsd host(g++ 3.4.6 [FreeBSD] 20060305) the output is: mofo mofo mofo error2!: mofo error2!: mofo error2!: and the depth is 5(which is what i wanted in the first place) btw, am i counting the depth right? so is my inserting function all wrong, or did i forget something, or do these things just happen? the whole code and input can be found here: http://rafb.net/p/9vEtMG46.html where oce_ == ancestor_ and sin_ == descendant the tree should look like this:
       -1
       20
   60      77
  0  1       666
      123       18


ty.

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!