I want to convert the recursive function given below:
LinkedList i=a; //a contains the nodes which are adjacent to the last element of g
for(String i1: i )
{
if(g.contains(i1) || i1.equals("o"))
{ continue; }
g.addLast(i1);
func(g);
g.removeLast();
}
I want to convert the above program to an iterative one. Can someone help
So walking through this it appears as though the steps are as follows:
1) Check for existence of current String or if it equals “o”
2a) If yes continue
2b) else put current string at end of list.
3) repeat steps 1->2
4) remove the last element of the list
If I were to make the code as simple as possible given those steps it would look like so: