-
September 28th, 2010, 12:31 PM
#1
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.
-
September 28th, 2010, 08:24 PM
#2
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
-
September 30th, 2010, 12:03 PM
#3
Re: Trees as Linked Lists
What's that?
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|