Please change this method to recursive method public String
Please change this method to recursive method.
public String postfix() {
final ExpressionNodes<String> nodes = new ExpressionNodes<String>();
for (String element : expression.split(\" \")) {
if (isOperator(element)) {
String rightNode = nodes.pop();
String leftNode = nodes.pop();
nodes.push((leftNode + \" \" + rightNode + \" \" + element));
} else {
nodes.push((element));
}
}
return nodes.pop();
}
Solution
public class Main{
public String postfix(int count)
final ExpressiononNodes <string> nodes = new ExpressiononNodes <string>();
for( String element : expression split(\" \"))
{
if (Is Operator(int element))
{
String rightNode = nodes.pop();
String leftNode = nodes.pop();
nodes.push((leftNode + \" \" + rightNode + \" \" +element));
}
else
{
nodes.push ((element));
}}
if (count <=0)
{
return nodes.pop();
}
else
{
postfix(count - 1);
}}
Public static void Main(String[] args)
{
Main n = new Main();
n.postfix(element);
}

