package sfsu;

import java.util.LinkedList;

public class LinkedTree2< T extends Comparable> implements Tree< T> {
private Node< T> root;
private int size;
class Node< T> {
private T data;
private Node< T> left, right;
}
@Override
public int getSize() {
// TODO Auto-generated method stub
return 0;
}
@Override
public T getParentValue(T x) {
// TODO Auto-generated method stub
return null;
}
@Override
public T getLeftValue(T x) {
// TODO Auto-generated method stub
return null;
}
@Override
public T getRightValue(T x) {
// TODO Auto-generated method stub
return null;
}
@Override
public String bfs() {
String s = "";
LinkedList< Node> q = new LinkedList< Node>();
return s;
}
@Override
public String preOrder() {
// TODO Auto-generated method stub
return null;
}
@Override
public String inOrder() {
// TODO Auto-generated method stub
return null;
}
@Override
public String postOrder() {
// TODO Auto-generated method stub
return null;
}
}
package sfsu;

public class TestTree {
public static void main(String[] args){
// create a full tree
String[] s1= {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L"};
Tree< String> t = new LinkedTree2< String>(s1); // new ArryTree< String>(s1) or new LinkedTree2< String>(s1)
System.out.println(t);
System.out.println("Find Parent of E: "+ t.getParentValue("E")); // output: B
System.out.println("Find Left Child of E: "+ t.getLeftValue("E")); // output: J
System.out.println("Find Right Child of E: "+ t.getRightValue("E")); // output: K

// traversal
System.out.println("BFS: "+t.bfs());
System.out.println("pre order traversal: "+t.preOrder());
System.out.println("in order traversal: "+t.inOrder());
System.out.println("post order traversal: "+t.postOrder());

// create a skewed tree
Integer[] i1= {1, 2, null, 4, null, null, null, 8};
Tree< Integer> t1 = new LinkedTree2< Integer>(i1); // new ArryTree< Integer>(i1) or new LinkedTree2 (i1)
System.out.println(t1);
System.out.println("Find Parent of 4: "+ t1.getParentValue(4));// output:2
System.out.println("Find Left Child of 4: "+ t1.getLeftValue(4));// output:8
System.out.println("Find Right Child of 4: "+ t1.getRightValue(4));// no right child

// traversal
System.out.println("BFS: "+t1.bfs());
System.out.println("pre order traversal: "+t1.preOrder());
System.out.println("in order traversal: "+t1.inOrder());
System.out.println("post order traversal: "+t1.postOrder());

}
}
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.