Question: This is my code for family tree, but i am confused on how to make a main class that will use these methods. public class

This is my code for family tree, but i am confused on how to make a main class that will use these methods.

public class FamilyTree

{

private class Node

{

String name;

Node next;

Node child;

public Node(String name)

{

this.name = name;

next = null;

child = null;

}

}

public Node addSibling(Node node, String name)

{

if(node == null)

return null;

while(node.next != null)

node = node.next;

return(node.next = new Node(name));

}

public Node addChild(Node node, String name)

{

if(node == null)

return null;

if(node.child != null)

return(addSibling(node.child,name));

else

return(node.child = new Node(name));

}

public void traverse(Node root)

{

if(root == null)

return;

while(root != null)

{

System.out.print(root.name + " ");

if(root.child != null)

traverse(root.child);

root = root.next;

}

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!