StringTree -...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: //******************************************************************** // StringTree.java Author: Lewis/Loftus // // Class that maintains a tree of Strings in lexigraphical order. //******************************************************************** / import java.util.Stack; import java.util.Scanner; i public class StringTree { //---------------------------------------------------------------- // Reference to the root node //---------------------------------------------------------------- public Node root; public StringTree() { root = null; } //---------------------------------------------------------------- // Adds a string to the tree //---------------------------------------------------------------- public void addString(String str) { root = addStringToSubTree(str, root); } //---------------------------------------------------------------- // Adds a string to the subtree with the given root node //---------------------------------------------------------------- private Node addStringToSubTree(String str, Node node) { Node result = node; if (node == null) { result = new Node(str); } // If the new string comes before the string in the node, add // the new string to the left child. Otherwise, add it to the// the new string to the left child....
View Full Document

Page1 / 3

StringTree -...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online