Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a class to implement a ternary tree node and another to implement a ternar

ID: 3739827 • Letter: W

Question

Write a class to implement a ternary tree node and another to implement a ternary search tree.

Each node has up to three children and two Comparable generic type data fields

Each left data field is either the only data field or less than the second data field.

Each member of the left subtree is less than the first data field value

Each member of the middle subtree is between the two data field values (greater than the first and less than the second)

Each member of the right subtree is greater than the second data field value

Just write methods to insert elements with no duplicates allowed, find a value in, and print out the tree using inorder (you do not need to use an Iterator).

If the root is null, add the new element as the first data in a new node and set the root equal to that.

If the new element is less than the first data, insert it in the left subtree

If there is no second data, add the new element as the second data.

If the new element is less than the second data, add it to the middle subtree

If the new element is greater than the second data, add it to the right subtree

Write a driver program to insert random Double values less than 100 and print them out, then test several calls to the find method.

this what i have so far

public class Nodes<T extends Comparable<T>> {

   private T data;

   private Nodes<T> kid1,kid2,kid3;

  

   public Nodes(T d){

       this.data=d;

   }

   public T getData(){

       return this.data;

   }

   public Nodes<T> getKid1(){

       return this.kid1;

   }

   public Nodes<T> getKid2(){

       return this.kid2;

   }

   public Nodes<T> getKid3(){

       return this.kid3;

   }

   public void setData(T d){

       this.data=d;

   }

   public void setKid1(Nodes<T> k1){

       this.kid1=k1;

   }

   public void setKid2(Nodes<T> k2){

       this.kid2=k2;

   }

   public void setKid3(Nodes<T> k3){

       this.kid3=k3;

   }

   public String toString(){

       return this.data + " ";

   }

}

public class ternarytree<T extends Comparable<T>> {

private Nodes<T> root;

private int count;

public ternarytree(){

  

}

public void insert(T newData){

   if(root==null)

       root=new Nodes<T>(newData);

   else{

       boolean inserted=false;

       Nodes<T>ptr=root;

       while(!inserted){

           if(ptr.getData().compareTo(newData)>0){

               if(ptr.getKid1()==null){

                   ptr.setKid1(new Nodes<T>(newData));

                   count++;

                   inserted=true;

               }

               else{

                   ptr=ptr.getKid1();

               }

              

           }

           else if (ptr.getData().compareTo(newData)<0){

               if()

           }

       }

   }

}

}

Write a class to implement a ternary tree node and another to implement a ternary search tree.

Each node has up to three children and two Comparable generic type data fields

Each left data field is either the only data field or less than the second data field.

Each member of the left subtree is less than the first data field value

Each member of the middle subtree is between the two data field values (greater than the first and less than the second)

Each member of the right subtree is greater than the second data field value

Just write methods to insert elements with no duplicates allowed, find a value in, and print out the tree using inorder (you do not need to use an Iterator).

Some cases for the insert method

If the root is null, add the new element as the first data in a new node and set the root equal to that.

If the new element is less than the first data, insert it in the left subtree

If the new element is greater than the first data,

If there is no second data, add the new element as the second data.

If there is second data,

If the new element is less than the second data, add it to the middle subtree

If the new element is greater than the second data, add it to the right subtree

Write a driver program to insert random Double values less than 100 and print them out, then test several calls to the find method.

this what i have so far

public class Nodes<T extends Comparable<T>> {

   private T data;

   private Nodes<T> kid1,kid2,kid3;

  

   public Nodes(T d){

       this.data=d;

   }

   public T getData(){

       return this.data;

   }

   public Nodes<T> getKid1(){

       return this.kid1;

   }

   public Nodes<T> getKid2(){

       return this.kid2;

   }

   public Nodes<T> getKid3(){

       return this.kid3;

   }

   public void setData(T d){

       this.data=d;

   }

   public void setKid1(Nodes<T> k1){

       this.kid1=k1;

   }

   public void setKid2(Nodes<T> k2){

       this.kid2=k2;

   }

   public void setKid3(Nodes<T> k3){

       this.kid3=k3;

   }

   public String toString(){

       return this.data + " ";

   }

}

public class ternarytree<T extends Comparable<T>> {

private Nodes<T> root;

private int count;

public ternarytree(){

  

}

public void insert(T newData){

   if(root==null)

       root=new Nodes<T>(newData);

   else{

       boolean inserted=false;

       Nodes<T>ptr=root;

       while(!inserted){

           if(ptr.getData().compareTo(newData)>0){

               if(ptr.getKid1()==null){

                   ptr.setKid1(new Nodes<T>(newData));

                   count++;

                   inserted=true;

               }

               else{

                   ptr=ptr.getKid1();

               }

              

           }

           else if (ptr.getData().compareTo(newData)<0){

               if()

           }

       }

   }

}

}

Explanation / Answer

import java.util.Scanner; import java.util.ArrayList; class TSTNode { char data; boolean isEnd; TSTNode left, middle, right; public TSTNode(char data) { this.data = data; this.isEnd = false; this.left = null; this.middle = null; this.right = null; } } class TernarySearchTree { private TSTNode root; private ArrayList al; public TernarySearchTree() { root = null; } public boolean isEmpty() { return root == null; } public void makeEmpty() { root = null; } public void insert(String word) { root = insert(root, word.toCharArray(), 0); } public TSTNode insert(TSTNode r, char[] word, int ptr) { if (r == null) r = new TSTNode(word[ptr]); if (word[ptr] r.data) r.right = insert(r.right, word, ptr); else { if (ptr + 1
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote