Given a string that contains ternary expressions. The expressions may be nested. You need to convert the given ternary expression to a binary Tree and return the root
All Answers
total answers (1)
Severity: 8192
Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
Filename: libraries/Filtered_db.php
Line Number: 23
total answers (1)
Ternary expression: In C, we are acquainted with the ternary expression. Ternary expressions are equivalent to the if-else statement in C.
Similarly, a ternary expression can be converted to a binary tree, where a will be the root, b will be the left child and c will be the right one. This small miniature can be expanded (followed) for nesting ternary expression.
The algorithm for constructing the binary tree from the ternary expression is:
Pre-requisite:
Algorithm:
Algorithm with example:
C++ implementation
Output