Sign in to follow this  
Thirthe

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

Recommended Posts

Thirthe    128
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[i]);
                        }
                        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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this