Question: Reimplement the composite design for the binary tree node class of Figure 5.11 using a flyweight in place of null pointers to empty nodes. In

Reimplement the composite design for the binary tree node class of Figure 5.11 using a flyweight in place of null pointers to empty nodes.

In Figure 5.11

public interface VarBinNode { public boolean isLeaf (); public void traverse (); } class VarLeaf Node

public interface VarBinNode { public boolean isLeaf (); public void traverse(); } class VarLeaf Node implements VarBinNode { // Leaf node private String operand; // Operand value public VarLeafNode (String val) { operand = val; } public boolean isLeaf () { return true; } public String value () { return operand; } public void traverse () { Visit. VisitLeafNode (operand); } class VarIntlNode implements VarBinNode { // Internal node private VarBinNode left; // Left child private VarBinNode right; // Right child private Character operator; // Operator value public VarIntlNode (Character op, VarBinNode 1, VarBinNode r) { operator = op; left = 1; right = r; } public boolean isLeaf () { return false; } public VarBinNode leftchild () { return left; } public VarBinNode right child () { return right; } public Character value () { return operator; } public void traverse () { Visit. Visit Internal Node (operator); } if (left != null) left.traverse (); if (right != null) right.traverse (); } /** Preorder traversal */ public static void traverse (VarBinNode rt) { if (rt != null) rt.traverse(); }

Step by Step Solution

3.43 Rating (175 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To reimplement the composite design for the binary tree node class of Figure 511 using a flyweight in place of null pointers to empty nodes you need t... 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 Practical Introduction To Data Structures Questions!