Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Creates Child and Siblings from Line in Input File
- public void addNodes(String[] values)
- {
- findNode(root, values[0]);
- Node node = foundNode;
- // If Child Node Exists, Purges it to Sibling and Creates New Child
- if(node.child != null)
- {
- node.sibling = node.child;
- node.child = null;
- }
- // Creates Child Nodes Under Each Subsequent Node Created
- for(int i = 1; i < values.length; i++)
- {
- if(node.child == null)
- {
- node.child = new Node(values[i]);
- }
- node = node.child;
- }
- }
- // Finds Parent Node for Node Child and Sibling Creation
- public void findNode(Node node, String value)
- {
- String newNode = node.value;
- String desiredValue = value;
- // If Parent Node Located, Sets Found Node
- if(newNode.equals(desiredValue))
- {
- foundNode = node;
- }
- // If Child Node Exists Search Child Node
- if(node.child != null)
- {
- findNode(node.child, value);
- }
- // If Sibling Node Exists Search Sibling Node
- if(node.sibling != null)
- {
- findNode(node.sibling, value);
- }
- }
Add Comment
Please, Sign In to add comment