This problem involves processing a prefix expression by constructing its syntax tree. The syntax tree is built using a base class STNode
and two derived classes: OperandNode
(for operands) and OperatorNode
(for operators).
The program should:
A
to Z
Your tasks are:
printNode()
and eval()
functions in the derived classes&
, |
and ^
, which represent bitwise AND, bitwise OR and bitwise XOR, respectivelyOperandNode
and OperatorNode
to properly delete all nodes in the treemakeNode(char)
of both derived classesOperandNode
, the function should take name
(the variable name) as inputOperatorNode
, the function should take op
(the operator) as input<<
operator to enable printing a node using cout
Hint: How to overload "cout <<" to print anything?
Hint: You may get RE or MLE if the destructor is not implemented correctly
The first line contain one integer $T$, representing the total number of testcases.
Following $2T$ lines, each testcase consists of $2$ lines
For each test case, output exactly two lines: