Ai
2 Star 0 Fork 0

CS-IMIS-23/20172302侯泽洋

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
PostfixTester.java 1.63 KB
Copy Edit Raw Blame History
20172302 authored 2018-10-27 20:30 +08:00 . 第十章——树课本代码及课本练习题
package chapter10;
import chapter10.jsjf.BinaryTreeNode;
import java.util.Scanner;
public class PostfixTester
{
public static void main(String[] args)
{
String expression, again;
int result;
Scanner in = new Scanner(System.in);
PostfixEvaluator evaluator = new PostfixEvaluator();
do
{
System.out.println("Enter a valid post-fix expression one token " +
"at a time with a space between each token (e.g. 5 4 + 3 2 1 - + *)");
System.out.println("Each token must be an integer or an operator (+,-,*,/)");
expression = in.nextLine();
result = evaluator.evaluate(expression);
System.out.println();
System.out.println("That expression equals " + result);
System.out.println("The Expression Tree for that expression is: ");
System.out.println(evaluator.getTree());
System.out.print("Evaluate another expression [Y/N]? ");
again = in.nextLine();
System.out.println();
ExpressionTreeOp expressionTreeOp = new ExpressionTreeOp(1,'+',0);
System.out.println("树中是否含指定元素数字1:"+evaluator.contains(expressionTreeOp));
BinaryTreeNode<ExpressionTreeOp> binaryTreeNode = evaluator.getRoot();
System.out.println(binaryTreeNode.isLeaf());
// evaluator.removeAllElements();
// System.out.println("删除树中所有元素后打印树:"+evaluator.getTree());
}
while (again.equalsIgnoreCase("y"));
System.out.println(evaluator.toString());
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/CS-IMIS-23/Java-pro.git
git@gitee.com:CS-IMIS-23/Java-pro.git
CS-IMIS-23
Java-pro
20172302侯泽洋
master

Search