Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In java, this is what i have so far, I need to add main with input and display the family tree. public class FamilyTree {

In java, this is what i have so far, I need to add main with input and display the family tree.

public class FamilyTree { private class Node { String value; Node left, right; Node(String val) { value = val; left = null; right = null; } Node(String val, Node leftChild, Node rightChild) { value = val; left = leftChild; right = rightChild; } } private Node root = null; public boolean root(String x) { if (root == null){ root = new Node(x); return true;} else return false; } public boolean addLeft(String p, String x) { Node parent = locate(p); if (root == null ){ return false;} else if (parent != null && parent.left == null){ parent.left = new Node(x); return true;} else return false; } public boolean addRight(String p, String x) { Node parent = locate(p); if (root == null ){ return false;} else if (parent != null && parent.right == null){ //Adds node parent.right = new Node(x); return true;} else return false; } public Node locate(String p) { return locate(p, root); } private Node locate(String p, Node famTree) { Node result = null; if (famTree == null) return null; if (famTree.value.equals(p)) return famTree; if (famTree.left != null) result = locate(p,famTree.left); if (result == null) result = locate(p,famTree.right); return result; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Seven Databases In Seven Weeks A Guide To Modern Databases And The NoSQL Movement

Authors: Luc Perkins, Eric Redmond, Jim Wilson

2nd Edition

1680502530, 978-1680502534

More Books

Students also viewed these Databases questions

Question

Provide examples of Dimensional Tables.

Answered: 1 week ago