the following code is recursive method i'm writing...
it walks through a binary tree that has stored a prefix expression such as (+ 2 (+2 3)) and is supposed to return it a infix expression like this (2 + (2 + 3)).
public String buildInfix(ETree pointer)
String myInfix ="";
if(pointer.getTypeOf() == 1)
ETree left = ((Internal)pointer).getLeft();
String store = buildInfix(left);
myInfix += "( " + store + " ";
myInfix += ((Character)((Internal)pointer).getObject()).charValue() + " ";
ETree right =((Internal)pointer).getRight();
store = buildInfix(right);
myInfix += store + " )";
if(pointer.getTypeOf() == 2) //found a Constant
int temp =((Integer)((Constant)pointer).getObject()).intValue();
String number = "" + temp;
if(pointer.getTypeOf() == 3) //found a Variable
String temp =(String)((Variable)pointer).getObject();
when i use a simple expression such as (+ 2 4) it work perfectly fine and returns (2 + 4)
but if i make it complicated like (+2 (* 2 3)) then the function gets caught in a infinite loop...
i noticed this when i put in some print statements...the function gets hung on the 2 and the +...the pointers don't seem to move on to the next value...
does anyone know why????
i'd really appreciate the help...