0
How to do only using recursion
Please refer code below : Main question is on visitall function. It has recursive call also and a for loop also... Can I avoid for loop and completely do recursive call only ? If yes , could you please let me know how to do so ? https://code.sololearn.com/c17n29Lr87xr/?ref=app
7 Respuestas
+ 1
This is what i came up with, but theres no benefit to using recursion vs simply a for loop
In my example*
https://code.sololearn.com/crnl4SYodEZC/?ref=app
+ 1
Ketan Lalcheta i used my phone but yeah most likely on sololearns end.
0
How you have things set up i dont think so.
Since each node has its own list, you need that for loop to navigate through each list.
so its basically stacking things like
for(node in root node list )
for (node in child list )
for ( node in child chid list)
… and so on
Print data
0
Ok... Is there other way to store this data to allow only recurring code ? Can u please suggest on this ?
0
Thanks Raul Ramirez but seems there is some issue in sololearn now a days...
I belive you have prepared this code on laptop and I am accessing this from android mobile app... I can find code incomplete so can't check code what has been done..
0
Don't know what happened since last few days...
Am I the only one who could see it first 25 lines into code ?
0
Raul Ramirez thanks for your answers..
I was just going through my previous questions... now i can check your full solution
Your solution works but requirement is to have list of list kind of n tree
You are adding all items to store object... that is not my requirement.
What i have as data structure is fix for storing data... can i still achieve visiting all either by only recursion or either by only iteration
Right now i am doing both (for loop and recursion call) .can i do using only one ?