Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,
I am currently developing a program in C++ which detects super node from a simple node in a ring type topology. My requirement is that I need to traverse from simple node to super node and highlight all the possible paths which are going to super node. This includes ring topology in between super node and simple node.

I would like to write a recursive function to find the path. Please let me know if anyone has any idea about how to develop recursive function which detects it.

I have attached linked these images for better understanding:

Starting.JPG[^]
Expected.JPG[^]
Posted
Updated 25-May-10 0:13am
v5
Comments
Michel Godfroid 10-May-10 11:30am    
Attaching images is not an option here. Either point us to some website which describes your data, or post your images on some free picture website and supply us with the link.
CPallini 10-May-10 14:11pm    
If you cannot post image links then give a bit more info about 'super node' and 'simple node' or possibly the data structure (you're using) representing them.
Moak 25-May-10 6:15am    
Updated text with image links, hope this helps.

Hi,
1.traverse from the node to find out all the parentnodes of the current node.

2.Keep all the nodes in a list.

3.Set recursive loop for all the parentnode one by one till the super node is not achieved.

4. Highlight the collected nodes.




Thanks,
Lokesh Balan

:)
 
Share this answer
 
Once you have the hierarchial structure of the nodes like a node has childnodes and the children has childrens then it is fir for a recursive search.

Say for example Node A has Child B and Child C. Say all the nodes has map childs function which will be recursively called and pass the path so far to the child. So here A call the recursive function in each child and pass path AB to B and AC to C.

Now say B has two children D & E, but C has no children. So C will return a null path. Instead B pass ABD to D and ABE to E. Now say D has a child H which is the end point. So D pass ABDH to H and as it is end point it returns the path. E has a child F and F has the child H (end point). So E pass ABEF to F and F pass ABEFH to H and it returns. So we got two paths ABDH and ABEFH, the AC path we will not get and the end child returns null, because it didn't reached the end point.

So that way you can get the final valid paths. Hope this helps
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900