package apz.co203;
import java.io.PrintStream;

public class ExprTree
{
    public ExprTree(Element[] pElements)
    {
        // Construct our tree
        // Create top node
        // The top node is always the last entry in our elements array
        TreeNode topNode = new TreeNode(null, pElements[pElements.length - 1]);




        System.out.println(topNode.getValue().getValue());
        System.out.println(getOperator(topNode.getValue().getValue()));

    }

    public void drawTree(PrintStream out)
    {

    }


    private boolean checkElement(String pValue)
    {
        // Checks to make sure element value is valid
        // Valid elements

    }

    private char getOperator(String pValue)
    {
        for(int i=0; i<pValue.length(); i++)
            if (isOperator(pValue.charAt(i))) return pValue.charAt(i);
        throw new Exception("Value doesn't contain operator");
    }

    private boolean isOperator(char pChar)
    {
        // Checks whether passed character is a mathmatical operator
        return ((pChar == '%') || (pChar == '^') || (pChar == '*') ||
            (pChar == '-') || (pChar == '+') || (pChar == '/'));
    }



}