Hi there, Java newbie here looking for some help. Here is the code in question:
public void generateCodeTable(Node tree, StringBuffer buf) {
if (tree != null) {
StringBuffer newSB = new StringBuffer();
newSB.append(buf);
if (tree.key != '$') {
System.out.print(tree.key + "(" + buf + ") " );
} else {
System.out.print(tree.key + "(" + buf + ") " );
}
generateCodeTable(tree.getLeftNode(), newSB.append(1));
generateCodeTable(tree.getRightNode(), newSB.append(0));
}
What this does is continually append to the SAME StringBuffer in every iteration of the recursive loop, when really what I'd like to be able to do it have it create a brand-new StringBuffer every time through. Any way to force a new StringBuffer to be created?
Hopefully that made sense; let me know where I can clarify. Thank you! :)