Where can we use "This" in Recursion methode...

Posted by T_Geek on Stack Overflow See other posts from Stack Overflow or by T_Geek
Published on 2010-03-31T02:35:17Z Indexed on 2010/12/23 3:54 UTC
Read the original article Hit count: 230

Hi . I have a methode in a static class which try to convert bi*nar*y tre to list

I'd like to make a recusion but I couldn't

I've implemented some opertation in my class like add,delet,find.it's too easy to implement its .

Here is the code

class ARB
{
        private:
                struct BT
                {
                        int data;
                        BT *l;
                        BT *r;
                };
                struct BT *p;
       public
                ARB();
                ~ARB();
                void del(int n);
                void add(int n); 
};

    void ARB::del(int num)
{
//The code ,don't care about it 

  };  

main()
{
// 
    BTR T;
    T.add(3);
    T.add(5);

};

Here is what should we do to transfert the code from Benary tree tolist

LLC ARB::changeit()
{   LLC x;
        while(this!=NULL)
        {
            x.add(this->data); //
                if(this.l==NULL)
                {
                       x.print(); //To print the elemnts of List
                        return(x);
                }
                else
                {
                        x=changeit(this.l);
                }

                if(this.r!=NULL)
                {
                       x.~LLC();
                       x=changeit(this.r);
                        return(x);
                }

        }

}

© Stack Overflow or respective owner

Related posts about c++

Related posts about visual-studio-2008