50字范文,内容丰富有趣,生活中的好帮手!
50字范文 > 表达式树 java_表达树—构建表达式树 获取表达式(二)

表达式树 java_表达树—构建表达式树 获取表达式(二)

时间:2022-09-30 10:38:04

相关推荐

表达式树 java_表达树—构建表达式树 获取表达式(二)

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;

}

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。