Problem in Tree, help!!

Hello friends, I am trying to fill one tree of three nodes at most, I have one function to add nodes to the tree:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void SkillTree :: AddSkill (char * name, char * desc, int level, char * ParentName)
{
Skill item (name, desc, level); / / the name is unique
TreeContains TreeNode * parent = (root, ParentName);

if (parent! = NULL)
{
if (parent-> left == NULL)
parent-> left = new TreeNode (item);
else if (parent-> middle == NULL)
parent-> middle = new TreeNode (item);
else if (parent-> right == NULL)
parent-> right = new TreeNode (item);
}
}


to find any node in the tree:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
TreeNode * SkillTree :: treeContains (TreeNode * root, char * ParentName)
{
    if (root == NULL) {
        return NULL;
    }
else if (strcmp (ParentName, root-> item.getName ()) == 0) {
        return root;
    }
else if (root-> left! = NULL && strcmp (ParentName, root-> left-> item.getName ()) == 0)
{
        treeContains return (root-> left, ParentName);
    }
else if (root-> middle! = NULL && strcmp (ParentName, root-> middle-> item.getName ()) == 0) {
treeContains return (root-> middle, ParentName);
    }
else if (root-> right! = NULL && strcmp (ParentName, root-> right-> item.getName ()) == 0) {
        treeContains return (root-> right, ParentName);
    }
return NULL;
}


to print the result:

1
2
3
4
5
6
7
8
9
void SkillTree :: inorderPrint (TreeNode * root) {
    if (root! = NULL)
    {
cout << root-> item.getName () << "-" << root-> item.getDescription () << "[Lvl:" << root-> item.getLevel () << "] \ n ";
        inorderPrint (root-> left);
inorderPrint (root-> middle);
        inorderPrint (root-> right);
    }
}

-------------------------------------------------- -------------------------
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
int main ()

SkillTree student ("Student");
student.Display (cout) / / calls the inorderPrint

student.AddSkill ("Alphabet", "Mastery of letters and sounds", 0);
student.Display (cout);

student.AddSkill ("Reading", "The Ability to read all manner of written material", 1, "Alphabet");
student.AddSkill ("Writing", "The Ability to put your thoughts on paper", 1, "Alphabet");
student.Display (cout);

student.AddSkill ("Speed ​​Reading Level 1", "Read any text twice as fast as normal", 5, "Reading");
student.AddSkill ("Speed ​​Reading Level 2", "Read any text four times as fast as normal", 10, "Speed ​​Reading Level 1");
student.AddSkill ("Memorization", "average sized Memorize texts", 10, "Reading");
student.AddSkill ("Massive Memorization", "Memorize large sized texts", 20, "Memorization");
student.AddSkill ("Spell Writing", "The Ability to write spells", 5, "Writing");
student.AddSkill ("History", "The Ability to write (and rewrite) history", 10, "Writing");
student.AddSkill ("Written Creation", "The Ability to write things into reality", 20, "History");
student.Display (cout);

-------------------------------------------------- -------------

The result I get is:
Skill Tree: Student
Empty
Skill Tree: Student
- Alphabet - Mastery of letters and sounds [Lvl: 0]
Skill Tree: Student
- Alphabet - Mastery of letters and sounds [Lvl: 0]
- Reading - The Ability to read all manner of written material [Lvl 1]
- Writing - The Ability to put your thoughts on paper [Lvl 1]
Skill Tree: Student
- Alphabet - Mastery of letters and sounds [Lvl: 0]
- Reading - The Ability to read all manner of written material [Lvl 1]
- Speed ​​Reading Level 1 - Read any text twice as fast as normal [Lvl: 5]
- Memorization - Memorize average sized texts [Lvl: 10]
- Writing - The Ability to put your thoughts on paper [Lvl 1]
- Spell Writing - The Ability to write spells [Lvl: 5]
- History - The Ability to write (and rewrite) history [Lvl: 10]
Press any key to continue. . .

and need:
Skill Tree: Student
Empty
Skill Tree: Student
- Alphabet - Mastery of letters and sounds [Lvl: 0]
Skill Tree: Student
- Alphabet - Mastery of letters and sounds [Lvl: 0]
- Reading - The Ability to read all manner of written material [Lvl 1]
- Writing - The Ability to put your thoughts on paper [Lvl 1]
Skill Tree: Student
- Alphabet - Mastery of letters and sounds [Lvl: 0]
- Reading - The Ability to read all manner of written material [Lvl 1]
- Speed ​​Reading Level 1 - Read any text twice as fast as normal [Lvl: 5]
- Speed ​​Reading Level 2 - Read any text four times as fast as normal [Lvl: 10]
- Memorization - Memorize average sized texts [Lvl: 10]
- Massive Memorization - Memorize large sized texts [Lvl: 20]
- Writing - The Ability to put your thoughts on paper [Lvl 1]
- Spell Writing - The Ability to write spells [Lvl: 5]
- History - The Ability to write (and rewrite) history [Lvl: 10]
- Written Creation - The Ability to write things into reality [Lvl: 20]


I have that problem????

regards
Rooster
Topic archived. No new replies allowed.