Question: Describe a modification to parenthesize, from Code Fragment 8.26, that relies on the length( ) method for the String class to output the parenthetic representation

Describe a modification to parenthesize, from Code Fragment 8.26, that relies on the length( ) method for the String class to output the parenthetic representation of a tree with line breaks added to display the tree in a text window that is 80 characters wide.

Fragment 8.26

1 /** Prints parenthesized representation of subtree of T rooted at p.

1 /** Prints parenthesized representation of subtree of T rooted at p. */ 2 public static void parenthesize(Tree T, Position p) { 3 System.out.print(p.getElement()); 4 if (T.islnternal(p)) { boolean first Time = true; for (Position c: T.children(p)) { System.out.print( (firstTime ? " (" : ", ") ); // determine proper punctuation first Time = false; parenthesize(T, c); } System.out.print(")"); } 5 7 8 // any future passes will get comma // recur on child 9 10 11 12 13 }

Step by Step Solution

3.39 Rating (171 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The modification to the parenthesize method in Code Fragment 826 can be made ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Introduction to Algorithms Questions!