Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. public boolean addChild(String ID, String parentID) {
  2. // TODO Auto-generated method stub
  3. // checks if array has any children
  4. if (!parentID.equals(id)) {
  5. //checks if array index 0 is empty
  6. if (children[0]!=null) {
  7.  
  8. return children[0].addChild(ID, parentID);
  9.  
  10. } else if(children[1]!=null) {
  11.  
  12. return children[1].addChild(ID, parentID);
  13. //no matching children were found
  14. } else {
  15. return false;
  16. }
  17.  
  18. }
  19. // else statement: a child matching the parent ID was found
  20. else {
  21. // checks if array has no children
  22. if (numofchildren == 0) {
  23. TreeDataStructure child = new TreeDataStructure(ID, parentID);
  24. numofchildren++;
  25. children[0] = child;
  26. return true;
  27. }
  28. // checks if array has 1 child
  29. else if (numofchildren == 1) {
  30. TreeDataStructure child = new TreeDataStructure(ID, parentID);
  31. numofchildren++;
  32. children[1] = child;
  33. return true;
  34. } else {
  35. return false;
  36. }
  37. }
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement