How to go back in a graph? - C #

0

create the following structure

  public class nodo
    {


        public string info = null;
        public nodo[] nodl = new nodo[2] ;



    }

nodo nod0=new nodo();
        nod0.info = "1";
        nodo nod1 = new nodo();
        nod1.info="2";
        nod0.nodl[0]=nod1;
        nodo nod2 = new nodo();
        nod2.info="3";
        nod0.nodl[1]=nod2;

graphically should have this form

           _nod0_
          !      ! 
          !      !
         nod1  nod2 

My question is with this structure I can stop at nod0.nodl [0] and go to fix with some travel the info of nod0 and nod2, that is to go up to nod0 and from there go to until no nod2, because I was trying to make binary trees with more branches and I can go through them with recursion. The problem is that I always have to stand at the root, but if I wanted to cross it from another point I would need another type of structure?

    
asked by Shiki 01.12.2017 в 14:50
source

1 answer

0

You comment that you have been able to walk through a tree (which is basically what you are doing) but when you go through the left side, it stops at the root?

To travel trees in full you have 3 methods that you can use according to  the order that interests you.

The tours are:

  • Pre-order travel
  • Inorder tour
  • Travel in postorden

With these 3 routes you pass through all the nodes of the tree as I said, in the order that you decide.

I'll give you the Wikipedia link so you can see how to do each route: link

    
answered by 01.12.2017 в 14:59