CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2010
    Posts
    3

    Trees as Linked Lists

    Hello
    How do I deal with Trees as Linked Lists ??

    View Photos,



    Uploaded with ImageShack.us


    I think I would need for TL* son ,TL* father, TL* brother.

    Code:
    struct ff
    {
            int id;
            ff * son;
            ff * father;
            ff * brother;
    };
    class formula_s
    {
            public:
                ~formula_s();
                formula_s();
                void add_formula(ff *p1);
    };
    I used to enter data this way,
    Code:
    		f = new formula;
    		f->id = 1;
    		g = new formula;
    		g->id = 11;
    		f->son = g;
    		g->father = f;
    		p = new formula;
    		p->id = 12;
    		g->brother = p;
    		p->father = g;
    		p->brother = NULL;
    		q = new formula;
    		q->id = 13;
    		p->son = q;
    		q->father = p;
    		p = new formula;
    		p->id = 14;
    		q->brother = p;
    		p->father = q;
    		p->brother = NULL;
    		p = new formula;
    		p->id = 15;
    		g->son = p;
    		p->father = g;
    		p->brother = NULL;
    I want to create a function >>> void add_formula(ff *p1);
    so as to the user can enter data.

  2. #2
    Join Date
    Jul 2010
    Posts
    31

    Re: Trees as Linked Lists

    Unless you make an actual, mutual interaction between nodes, you won't be able to build anything on your own; No one is helping you except you

  3. #3
    Join Date
    Jan 2008
    Location
    California, USA
    Posts
    822

    Re: Trees as Linked Lists

    mutual interaction
    What's that?
    Quote Originally Posted by Jeneo W.
    I want to create a function >>> void add_formula(ff *p1);
    so as to the user can enter data.
    well, you already know how to assign a pointer
    Code:
    #include <iostream>
    
    namespace demo
    {
    std::ostream& os = std::cout;
    
    struct formula
    {
        explicit
        formula(const int i = 0)
            :
            next(0),
            previous(0),
            id(i)
        {
        }
    
        formula* next;
        formula* previous;
        int id;
    };
    
    struct mixer
    {
        mixer()
            : pointer(0)
        {
        }
    
        void add_formula(formula* p)
        {
            pointer = p;
            os << "Formula id ( " << p->id << " ) added\n";
        }
    
        formula*  pointer;
    };
    
    } // end namespace
    
    int main()
    {
        {
            using namespace demo;
    
            formula f(66);
            formula f2(77);
    
            mixer m;
            m.add_formula(&f);
            m.add_formula(&f2);
        }
    }
    Or do I silently hear you having trouble with other stuff you haven't said yet?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured