Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public boolean addChild(String ID, String parentID) {
- // TODO Auto-generated method stub
- // checks if array has any children
- if (!parentID.equals(id)) {
- //checks if array index 0 is empty
- if (children[0]!=null) {
- return children[0].addChild(ID, parentID);
- } else if(children[1]!=null) {
- return children[1].addChild(ID, parentID);
- //no matching children were found
- } else {
- return false;
- }
- }
- // else statement: a child matching the parent ID was found
- else {
- // checks if array has no children
- if (numofchildren == 0) {
- TreeDataStructure child = new TreeDataStructure(ID, parentID);
- numofchildren++;
- children[0] = child;
- return true;
- }
- // checks if array has 1 child
- else if (numofchildren == 1) {
- TreeDataStructure child = new TreeDataStructure(ID, parentID);
- numofchildren++;
- children[1] = child;
- return true;
- } else {
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement