Guest User

Untitled

a guest
Jul 20th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. // Creates Child and Siblings from Line in Input File
  2. public void addNodes(String[] values)
  3. {
  4.  
  5. findNode(root, values[0]);
  6. Node node = foundNode;
  7.  
  8. // If Child Node Exists, Purges it to Sibling and Creates New Child
  9. if(node.child != null)
  10. {
  11. node.sibling = node.child;
  12. node.child = null;
  13. }
  14.  
  15. // Creates Child Nodes Under Each Subsequent Node Created
  16. for(int i = 1; i < values.length; i++)
  17. {
  18. if(node.child == null)
  19. {
  20. node.child = new Node(values[i]);
  21. }
  22.  
  23. node = node.child;
  24. }
  25. }
  26.  
  27. // Finds Parent Node for Node Child and Sibling Creation
  28. public void findNode(Node node, String value)
  29. {
  30.  
  31. String newNode = node.value;
  32. String desiredValue = value;
  33.  
  34. // If Parent Node Located, Sets Found Node
  35. if(newNode.equals(desiredValue))
  36. {
  37. foundNode = node;
  38. }
  39.  
  40. // If Child Node Exists Search Child Node
  41. if(node.child != null)
  42. {
  43. findNode(node.child, value);
  44. }
  45.  
  46. // If Sibling Node Exists Search Sibling Node
  47. if(node.sibling != null)
  48. {
  49. findNode(node.sibling, value);
  50. }
  51.  
  52. }
Add Comment
Please, Sign In to add comment