Tutorial :How to traverse a trie longitudinally?



Question:

i have a Trie and several functions modifiing it.

typedef struct node *pnode;    typedef struct node  {      int element;      pnode next;//same level, other element      pnode subtree;//next level  } node;  

Now, in order to debug and/or test my functions, I need to print out the tries.

I tried it recursively, but I cannot get the first level, than the second level...

What's a good way to do it?


Solution:1

Instead of using stack (or emulating it with recurrence), you have to use queue.

http://en.wikipedia.org/wiki/Breadth-first_search


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »