Jump to content

Tree c language

- - - - -

  • Please log in to reply
3 replies to this topic

#1
Apprentice123

Apprentice123

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 430 posts

typedef char info; 

typedef struct node Tree;

struct node { 

  info dado;

  Tree *firstSon; 

  Tree *nextBrother;

}; 


void InsertsRoot();


How can I enter in the root if I have firstSon and nextBrother ?

#2
Ancient Dragon

Ancient Dragon

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 400 posts
You can't. That is a one-way tree, not a circular or bydirectional tree. You would have to add a parent link if you want to get to the root from any where within the tree.
Visit Grandpa's Forums, a social networking forum, with family-oriented arcade games, blogs, discussion forums, and photo albums.

#3
Apprentice123

Apprentice123

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 430 posts

Ancient Dragon said:

You can't. That is a one-way tree, not a circular or bydirectional tree. You would have to add a parent link if you want to get to the root from any where within the tree.

It's not correct ?

void InsertsRoot()

{

       Tree *root;

       root = (Tree*) malloc(sizeof(Tree));

       root->firstSon = NULL;

       root->nextBrother = NULL;

}



#4
Ancient Dragon

Ancient Dragon

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 400 posts
What you have is ok, but you can't get back to root from firstSon or nextBrother.
Visit Grandpa's Forums, a social networking forum, with family-oriented arcade games, blogs, discussion forums, and photo albums.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users