Hot Search : Source embeded web remote control p2p game More...
Location : Home Search - syntax tree in C
Search - syntax tree in C - List
一个表达式和一棵二叉树之间,存在着自然的对应关系。写一个程序,实现基于二叉树表示的算术表达式Expression的操作。 【基本要求】 【一】【必做部分】 假设算术表达式Expression内可以含有变量(a-z),常量(0-9)和二元运算符(+,-,*,/,^(乘幂))。实现以下操作: (1)ReadExpr(E)――以字符序列的形式输入语法正确的前缀表达式并构造表达式E。 (2)WriteExpr(E)――用带括号的中缀表达式输出表达式E。 (3)Assign(V,c)――实现对变量V的赋值(V=c),变量的初值为0。 (4)Value(E)――对算术表达式E求值。 (5)CompoundExpr(p,E1,E2)――构造一个新的复合表达式(E1)p(E2)。 【二】【选做部分】 (1)以表达式的原书写形式输入,支持大于0的正整数常量; (2)增加常数合并操作MergeConst(E)——合并表达式E中所有常数运算。例如,对表达式E=(2+3-a)*(b+3*4)进行合并常数的操作后,求得E=(5-a)*(b+12) 【测试数据】 1) 分别输入0;a -91 +a*bc +*5x2*8x +++*3^*2^x2x6并输出。 2) 每当输入一个表达式后,对其中的变量赋值,然后对表达式求值。 3) 还有很多测试的数据,详细请见附上的文件Test.txt。 -Between an expression and a binary tree, there is a natural correspondence. Write a program to realize the arithmetic expression based on Binary Tree for Expression of the operation. Basic requirements of】 【 【1】 【will do some】 Suppose an arithmetic expression can contain variables in Expression (az), constant (0-9) and the binary operator (+,-,*,/,^( power)). To achieve the following: (1) ReadExpr (E)- in the form of a sequence of characters enter the correct prefix expression syntax and constructs the expression E. (2) WriteExpr (E)- with the infix expression with parentheses output expression E. (3) Assign (V, c)- to achieve the assignment of the variable V (V = c), the variable s initial value is 0. (4) Value (E)- E evaluation of arithmetic expressions. (5) CompoundExpr (p, E1, E2)- construct a new complex expression (E1) p (E2). 【2】 【choose to do some】 (1) the original written form of expression input, support for constant positive integer greater than 0 (2)
Date : 2025-12-16 Size : 245kb User : snake
CodeBus is one of the largest source code repositories on the Internet!
Contact us :
1999-2046 CodeBus All Rights Reserved.