1

I have some a string which needed to be evaluated in following pattern -

Input  => String testTree = "(1(2(4)())(3))";   
Output => {1,2,3,4,*,*,*}

Input  => String testTree2 = "(1(2(4)(5))(3()(4()(3))))";   
Output => {1,2,3,4,5,*,4,*,*,*,*,*,*,*,3}

Input  => String testTree3 = "(1()())";   
Output =>{1,*,*}

Above mention inputs have same pattern , where '()' or null is represented as '*'.Output is been saved to a int/string array , hence output form is like so.

Kindly suggest a method to evaluate such kind of pattern to the output form.

Being Coder
  • 127
  • 2
  • 10

1 Answers1

1

You could use the Interpreter pattern to read the input into a binary tree class.

Waog
  • 7,127
  • 5
  • 25
  • 37