List Trees and Recursive functions
Posted: Tue Apr 05, 2016 8:50 am
Hello,
Struggling with a recursive function, always found them difficult to follow, can anyone come up with the function here?
Okay lets suppose I have 3 list trees, lets give them names, winlayout-1, winlayout-2 and winlayout-3.
Each of the list trees has an arrangement of nodes and leafs on them already with various names, but each node id has the name winlayout-XXX - where XXX is a randomly number from 0 to 999 padded to 3 digits, e.g. winlayout-067, winlayout-999 etc...
Now, suppose the user wants to create a new leaf on winlayout-2 so he hits a button.
The button calls the function we are trying to create, it generates a new id winlayout-XXX and traverses all 3 list trees to find out whether any nodes or leafs currently have this id.
If it finds a node or leaf already with this id it generates a new id winlayout-XXX and traverses all 3 list trees again until it finds no matches within the list trees.
The function will return two parameters 'state' and 'result'.
If 'state' is True it means that a new unique ID has been generated with the id stored in 'result'. If the 'state' is False, it means there are already 999 leafs or nodes in the structure so no new id has been generated - i.e. The List Trees are full.
I really need to get to the bottom of this and having a working function so any help much appreciated!
Struggling with a recursive function, always found them difficult to follow, can anyone come up with the function here?
Okay lets suppose I have 3 list trees, lets give them names, winlayout-1, winlayout-2 and winlayout-3.
Each of the list trees has an arrangement of nodes and leafs on them already with various names, but each node id has the name winlayout-XXX - where XXX is a randomly number from 0 to 999 padded to 3 digits, e.g. winlayout-067, winlayout-999 etc...
Now, suppose the user wants to create a new leaf on winlayout-2 so he hits a button.
The button calls the function we are trying to create, it generates a new id winlayout-XXX and traverses all 3 list trees to find out whether any nodes or leafs currently have this id.
If it finds a node or leaf already with this id it generates a new id winlayout-XXX and traverses all 3 list trees again until it finds no matches within the list trees.
The function will return two parameters 'state' and 'result'.
If 'state' is True it means that a new unique ID has been generated with the id stored in 'result'. If the 'state' is False, it means there are already 999 leafs or nodes in the structure so no new id has been generated - i.e. The List Trees are full.
I really need to get to the bottom of this and having a working function so any help much appreciated!