public classExprTree {//最后访问头结点
public BinaryTreeNode buildExprTree(char postfixExpr[],intsize){
LinkedList stack=newLinkedList();
BinaryTreeNode node=null;for(int i=0;i
node=newBinaryTreeNode();
node.setLeft(null);
node.setRight(null);
node.setData(postfixExpr[i]);
stack.push(node);
}else{
BinaryTreeNode leftChild=stack.pop();
BinaryTreeNode rightChild=stack.pop();
node=newBinaryTreeNode();
node.setLeft(leftChild);
node.setRight(rightChild);
node.setData(postfixExpr[i]);
stack.push(node);
}
}returnstack.getLast();
}
//判断是否是操作数
private boolean isOperateNum(char c){
if(c=='/'||c=='+'||c=='*'||c=='-'){
return false;
}
return true;
}
}