SlideShare a Scribd company logo
1 of 5
Please finish everything marked TODO
BinaryNode.java
public class BinaryNode<E extends Comparable<E>> implements TreePrinter.PrintableNode{
private E data;
private BinaryNode<E> left;
private BinaryNode<E> right;
private int height;
private int size;
private BinaryNode<E> parent;
public BinaryNode(E data){
this.data = data;
this.left = null;
this.right = null;
this.parent = null;
this.height = 1;
this.size = 1;
}
// TODO: Set up the BinaryNode
public BinaryNode(E data, BinaryNode<E> left, BinaryNode<E> right, BinaryNode<E>
parent){
}
// Access fields
E data() { return this.data; };
BinaryNode<E> left() {
return this.left;
}
BinaryNode<E> right() {
return this.right;
}
BinaryNode<E> parent() { return this.parent; }
// Setter fields
void setLeft(BinaryNode<E> left) {
this.left = left;
if(left != null) left.setParent(this);
}
void setRight(BinaryNode<E> right) {
this.right = right;
if(right != null) right.setParent(this);
}
void setParent(BinaryNode<E> parent) {
this.parent = parent;
}
void setData(E data) { this.data = data; }
void setHeight(int h){
this.height = h;
}
// Basic properties
int height() {
return this.height;
}
int size() { return this.size; }
boolean isBalanced() {
int leftHeight = (hasLeft()) ? left.height() : 0;
int rightHeight = (hasRight()) ? right().height() : 0;
return Math.abs(leftHeight - rightHeight) < 2;
}
boolean hasLeft(){
return left == null ? false : true;
}
boolean hasRight(){
return right == null ? false :true;
}
boolean hasParent(){
return parent == null ? false :true;
}
public boolean equals(BinaryNode<E> other){
if(other == null) return false;
return other.data.equals(this.data);
}
// Can use these to help debug
public TreePrinter.PrintableNode getLeft() {
return left == null ? null : left;
}
public TreePrinter.PrintableNode getRight() {
return right == null ? null : right;
}
public String getText() {
return String.valueOf(data);
}
public String toString(){
String ret = "";
return "root " + this.data + " Left: " +(hasLeft() ? left.data : null) + " Right: " +(hasRight() ?
right.data : null) +
" parent: " + (hasParent() ? parent.data : null) ;
}
}
BST.java
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public class BST<E extends Comparable<E>> implements Tree<E> {
private int height;
private int size;
private BinaryNode<E> root;
public BST(){
this.root = null;
this.height = 0;
this.size = 0;
}
// TODO: BST
public BST(BinaryNode<E> root){
}
// Access field
public BinaryNode<E> root() {
return this.root;
}
// Basic properties
public int height() {
return this.height;
}
public int size() {
return this.size;
}
public boolean isBalanced() {
return root.isBalanced();
}
// TODO: updateHeight - Update the root height to reflect any changes
public void updateHeight() {
}
// Traversals that return lists
// TODO: Preorder traversal
public List<E> preOrderList() {
return new ArrayList<>();
}
// TODO: Inorder traversal
public List<E> inOrderList() {
return new ArrayList<>();
}
// TODO: Postorder traversal
public List<E> postOrderList() {
return new ArrayList<>();
}
// Helpers for BST/AVL methods
// TODO: extractRightMost
// This will be called on the left subtree and will get the maximum value.
public BinaryNode<E> extractRightMost(BinaryNode<E> curNode) {
return null;
}
// AVL & BST Search & insert same
// TODO: search
public BinaryNode<E> search(E elem) {
return null;
}
// TODO: insert
public void insert(E elem) {
}
// TODO: delete
public BinaryNode<E> delete(E elem) {
return null;
}
// Stuff to help you debug if you want
// Can ignore or use to see if it works.
static <E extends Comparable<E>> Tree<E> mkBST (Collection<E> elems) {
Tree<E> result = new BST<>();
for (E e : elems) result.insert(e);
return result;
}
public TreePrinter.PrintableNode getLeft() {
return this.root.hasLeft() ? this.root.left() : null;
}
public TreePrinter.PrintableNode getRight() {
return this.root.hasRight() ? this.root.right() : null;
}
public String getText() {
return (this.root != null) ? this.root.getText() : "";
}
}

More Related Content

Similar to Please finish everything marked TODO BinaryNode-java public class Bi.docx

Given BinaryNode.javapackage util;import java.util.;T.pdf
Given BinaryNode.javapackage util;import java.util.;T.pdfGiven BinaryNode.javapackage util;import java.util.;T.pdf
Given BinaryNode.javapackage util;import java.util.;T.pdfConint29
 
Given below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdfGiven below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdfinfo430661
 
So I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdfSo I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdfaksahnan
 
Given the following codepackage data1;import java.util.;p.pdf
Given the following codepackage data1;import java.util.;p.pdfGiven the following codepackage data1;import java.util.;p.pdf
Given the following codepackage data1;import java.util.;p.pdfillyasraja7
 
Create a class BinarySearchTree- A class that implements the ADT binar.pdf
Create a class BinarySearchTree- A class that implements the ADT binar.pdfCreate a class BinarySearchTree- A class that implements the ADT binar.pdf
Create a class BinarySearchTree- A class that implements the ADT binar.pdfshyamsunder1211
 
03.DS_Store__MACOSX03._.DS_Store03A2.DS_Store__.docx
03.DS_Store__MACOSX03._.DS_Store03A2.DS_Store__.docx03.DS_Store__MACOSX03._.DS_Store03A2.DS_Store__.docx
03.DS_Store__MACOSX03._.DS_Store03A2.DS_Store__.docxhoney725342
 
4. The size of instructions can be fixed or variable. What are advant.pdf
4. The size of instructions can be fixed or variable. What are advant.pdf4. The size of instructions can be fixed or variable. What are advant.pdf
4. The size of instructions can be fixed or variable. What are advant.pdfmumnesh
 
I need help implementing a Stack with this java programming assignme.pdf
I need help implementing a Stack with this java programming assignme.pdfI need help implementing a Stack with this java programming assignme.pdf
I need help implementing a Stack with this java programming assignme.pdfsauravmanwanicp
 
hi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdfhi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdfarchgeetsenterprises
 
usingpackage util;import java.util.;This class implements.pdf
usingpackage util;import java.util.;This class implements.pdfusingpackage util;import java.util.;This class implements.pdf
usingpackage util;import java.util.;This class implements.pdfinfo335653
 
For this project, write a program that stores integers in a binary.docx
For this project, write a program that stores integers in a binary.docxFor this project, write a program that stores integers in a binary.docx
For this project, write a program that stores integers in a binary.docxbudbarber38650
 
Step 1 The Pair Class Many times in writing software we come across p.pdf
Step 1 The Pair Class Many times in writing software we come across p.pdfStep 1 The Pair Class Many times in writing software we come across p.pdf
Step 1 The Pair Class Many times in writing software we come across p.pdfformaxekochi
 
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdfModify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdfarjuncorner565
 
in this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfin this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfmichardsonkhaicarr37
 
Java9 Beyond Modularity - Java 9 más allá de la modularidad
Java9 Beyond Modularity - Java 9 más allá de la modularidadJava9 Beyond Modularity - Java 9 más allá de la modularidad
Java9 Beyond Modularity - Java 9 más allá de la modularidadDavid Gómez García
 
Please write in C++ and should be able to compile and debug.Thank yo.pdf
Please write in C++ and should be able to compile and debug.Thank yo.pdfPlease write in C++ and should be able to compile and debug.Thank yo.pdf
Please write in C++ and should be able to compile and debug.Thank yo.pdfajaycosmeticslg
 
This is to test a balanced tree. I need help testing an unbalanced t.pdf
This is to test a balanced tree. I need help testing an unbalanced t.pdfThis is to test a balanced tree. I need help testing an unbalanced t.pdf
This is to test a balanced tree. I need help testing an unbalanced t.pdfakaluza07
 
Please read the comment ins codeExpressionTree.java-------------.pdf
Please read the comment ins codeExpressionTree.java-------------.pdfPlease read the comment ins codeExpressionTree.java-------------.pdf
Please read the comment ins codeExpressionTree.java-------------.pdfshanki7
 
5. Design and implement a method contains 2 for BinarySearchTree, fu.pdf
5. Design and implement a method contains 2 for BinarySearchTree, fu.pdf5. Design and implement a method contains 2 for BinarySearchTree, fu.pdf
5. Design and implement a method contains 2 for BinarySearchTree, fu.pdframbagra74
 
C# Application program UNIT III
C# Application program UNIT IIIC# Application program UNIT III
C# Application program UNIT IIIMinu Rajasekaran
 

Similar to Please finish everything marked TODO BinaryNode-java public class Bi.docx (20)

Given BinaryNode.javapackage util;import java.util.;T.pdf
Given BinaryNode.javapackage util;import java.util.;T.pdfGiven BinaryNode.javapackage util;import java.util.;T.pdf
Given BinaryNode.javapackage util;import java.util.;T.pdf
 
Given below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdfGiven below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdf
 
So I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdfSo I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdf
 
Given the following codepackage data1;import java.util.;p.pdf
Given the following codepackage data1;import java.util.;p.pdfGiven the following codepackage data1;import java.util.;p.pdf
Given the following codepackage data1;import java.util.;p.pdf
 
Create a class BinarySearchTree- A class that implements the ADT binar.pdf
Create a class BinarySearchTree- A class that implements the ADT binar.pdfCreate a class BinarySearchTree- A class that implements the ADT binar.pdf
Create a class BinarySearchTree- A class that implements the ADT binar.pdf
 
03.DS_Store__MACOSX03._.DS_Store03A2.DS_Store__.docx
03.DS_Store__MACOSX03._.DS_Store03A2.DS_Store__.docx03.DS_Store__MACOSX03._.DS_Store03A2.DS_Store__.docx
03.DS_Store__MACOSX03._.DS_Store03A2.DS_Store__.docx
 
4. The size of instructions can be fixed or variable. What are advant.pdf
4. The size of instructions can be fixed or variable. What are advant.pdf4. The size of instructions can be fixed or variable. What are advant.pdf
4. The size of instructions can be fixed or variable. What are advant.pdf
 
I need help implementing a Stack with this java programming assignme.pdf
I need help implementing a Stack with this java programming assignme.pdfI need help implementing a Stack with this java programming assignme.pdf
I need help implementing a Stack with this java programming assignme.pdf
 
hi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdfhi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdf
 
usingpackage util;import java.util.;This class implements.pdf
usingpackage util;import java.util.;This class implements.pdfusingpackage util;import java.util.;This class implements.pdf
usingpackage util;import java.util.;This class implements.pdf
 
For this project, write a program that stores integers in a binary.docx
For this project, write a program that stores integers in a binary.docxFor this project, write a program that stores integers in a binary.docx
For this project, write a program that stores integers in a binary.docx
 
Step 1 The Pair Class Many times in writing software we come across p.pdf
Step 1 The Pair Class Many times in writing software we come across p.pdfStep 1 The Pair Class Many times in writing software we come across p.pdf
Step 1 The Pair Class Many times in writing software we come across p.pdf
 
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdfModify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
 
in this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfin this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdf
 
Java9 Beyond Modularity - Java 9 más allá de la modularidad
Java9 Beyond Modularity - Java 9 más allá de la modularidadJava9 Beyond Modularity - Java 9 más allá de la modularidad
Java9 Beyond Modularity - Java 9 más allá de la modularidad
 
Please write in C++ and should be able to compile and debug.Thank yo.pdf
Please write in C++ and should be able to compile and debug.Thank yo.pdfPlease write in C++ and should be able to compile and debug.Thank yo.pdf
Please write in C++ and should be able to compile and debug.Thank yo.pdf
 
This is to test a balanced tree. I need help testing an unbalanced t.pdf
This is to test a balanced tree. I need help testing an unbalanced t.pdfThis is to test a balanced tree. I need help testing an unbalanced t.pdf
This is to test a balanced tree. I need help testing an unbalanced t.pdf
 
Please read the comment ins codeExpressionTree.java-------------.pdf
Please read the comment ins codeExpressionTree.java-------------.pdfPlease read the comment ins codeExpressionTree.java-------------.pdf
Please read the comment ins codeExpressionTree.java-------------.pdf
 
5. Design and implement a method contains 2 for BinarySearchTree, fu.pdf
5. Design and implement a method contains 2 for BinarySearchTree, fu.pdf5. Design and implement a method contains 2 for BinarySearchTree, fu.pdf
5. Design and implement a method contains 2 for BinarySearchTree, fu.pdf
 
C# Application program UNIT III
C# Application program UNIT IIIC# Application program UNIT III
C# Application program UNIT III
 

More from JakeT2gGrayp

Please discuss the bone growth abnormality achondroplasia (achondropla.docx
Please discuss the bone growth abnormality achondroplasia (achondropla.docxPlease discuss the bone growth abnormality achondroplasia (achondropla.docx
Please discuss the bone growth abnormality achondroplasia (achondropla.docxJakeT2gGrayp
 
Please answer all questions- Will upvote! Profitability ratios help in.docx
Please answer all questions- Will upvote! Profitability ratios help in.docxPlease answer all questions- Will upvote! Profitability ratios help in.docx
Please answer all questions- Will upvote! Profitability ratios help in.docxJakeT2gGrayp
 
picture of artery and vein to label i need a plain diagram of arteries.docx
picture of artery and vein to label i need a plain diagram of arteries.docxpicture of artery and vein to label i need a plain diagram of arteries.docx
picture of artery and vein to label i need a plain diagram of arteries.docxJakeT2gGrayp
 
Please answer all questions- 1) Adaptive immunity has five distinct a.docx
Please answer all questions-  1) Adaptive immunity has five distinct a.docxPlease answer all questions-  1) Adaptive immunity has five distinct a.docx
Please answer all questions- 1) Adaptive immunity has five distinct a.docxJakeT2gGrayp
 
Photoreceptors respond to the removal of light by Group of answer choi.docx
Photoreceptors respond to the removal of light by Group of answer choi.docxPhotoreceptors respond to the removal of light by Group of answer choi.docx
Photoreceptors respond to the removal of light by Group of answer choi.docxJakeT2gGrayp
 
Please answer all questions- IMMUNIZATION Immunization or vaccination.docx
Please answer all questions-  IMMUNIZATION Immunization or vaccination.docxPlease answer all questions-  IMMUNIZATION Immunization or vaccination.docx
Please answer all questions- IMMUNIZATION Immunization or vaccination.docxJakeT2gGrayp
 
Place these phases of an audit in chronological order- A- Assess the r.docx
Place these phases of an audit in chronological order- A- Assess the r.docxPlace these phases of an audit in chronological order- A- Assess the r.docx
Place these phases of an audit in chronological order- A- Assess the r.docxJakeT2gGrayp
 
Petty Cash Fund Petty Cash Fund Libby Company established a petty cas.docx
Petty Cash Fund  Petty Cash Fund Libby Company established a petty cas.docxPetty Cash Fund  Petty Cash Fund Libby Company established a petty cas.docx
Petty Cash Fund Petty Cash Fund Libby Company established a petty cas.docxJakeT2gGrayp
 
Please answer question 4b only 4- The image below (on Endomembrane Sys.docx
Please answer question 4b only 4- The image below (on Endomembrane Sys.docxPlease answer question 4b only 4- The image below (on Endomembrane Sys.docx
Please answer question 4b only 4- The image below (on Endomembrane Sys.docxJakeT2gGrayp
 
Please answer all questions- b- The in which CD95L binds to CD95 on t.docx
Please answer all questions-  b- The in which CD95L binds to CD95 on t.docxPlease answer all questions-  b- The in which CD95L binds to CD95 on t.docx
Please answer all questions- b- The in which CD95L binds to CD95 on t.docxJakeT2gGrayp
 
Please answer all questions- T Lymphocytes (T Cells) 1) T lymphocytes.docx
Please answer all questions-  T Lymphocytes (T Cells) 1) T lymphocytes.docxPlease answer all questions-  T Lymphocytes (T Cells) 1) T lymphocytes.docx
Please answer all questions- T Lymphocytes (T Cells) 1) T lymphocytes.docxJakeT2gGrayp
 
Please answer all questions- 5- When the inflammatory mediators excee (1).docx
Please answer all questions-  5- When the inflammatory mediators excee (1).docxPlease answer all questions-  5- When the inflammatory mediators excee (1).docx
Please answer all questions- 5- When the inflammatory mediators excee (1).docxJakeT2gGrayp
 
Please answer all questions- 10- Antibody Function- The binding of an.docx
Please answer all questions-  10- Antibody Function- The binding of an.docxPlease answer all questions-  10- Antibody Function- The binding of an.docx
Please answer all questions- 10- Antibody Function- The binding of an.docxJakeT2gGrayp
 
Phosphatidate is an intermediate in the formation of- a) phospholipids.docx
Phosphatidate is an intermediate in the formation of- a) phospholipids.docxPhosphatidate is an intermediate in the formation of- a) phospholipids.docx
Phosphatidate is an intermediate in the formation of- a) phospholipids.docxJakeT2gGrayp
 
phage type of 42D- Which statement(s) are true- Check All That Apply T.docx
phage type of 42D- Which statement(s) are true- Check All That Apply T.docxphage type of 42D- Which statement(s) are true- Check All That Apply T.docx
phage type of 42D- Which statement(s) are true- Check All That Apply T.docxJakeT2gGrayp
 
Pequired informetion Learning Objective 03-P6- Prepare closing entries.docx
Pequired informetion Learning Objective 03-P6- Prepare closing entries.docxPequired informetion Learning Objective 03-P6- Prepare closing entries.docx
Pequired informetion Learning Objective 03-P6- Prepare closing entries.docxJakeT2gGrayp
 
Please update the registers at the end of the program execution- Also.docx
Please update the registers at the end of the program execution- Also.docxPlease update the registers at the end of the program execution- Also.docx
Please update the registers at the end of the program execution- Also.docxJakeT2gGrayp
 
Please see below H10 table released by the Fed- Rates in currency unit.docx
Please see below H10 table released by the Fed- Rates in currency unit.docxPlease see below H10 table released by the Fed- Rates in currency unit.docx
Please see below H10 table released by the Fed- Rates in currency unit.docxJakeT2gGrayp
 
People are perceived as being more trustworthy when they- Select one-.docx
People are perceived as being more trustworthy when they- Select one-.docxPeople are perceived as being more trustworthy when they- Select one-.docx
People are perceived as being more trustworthy when they- Select one-.docxJakeT2gGrayp
 
Please make revision to the following program so it incorporates three.docx
Please make revision to the following program so it incorporates three.docxPlease make revision to the following program so it incorporates three.docx
Please make revision to the following program so it incorporates three.docxJakeT2gGrayp
 

More from JakeT2gGrayp (20)

Please discuss the bone growth abnormality achondroplasia (achondropla.docx
Please discuss the bone growth abnormality achondroplasia (achondropla.docxPlease discuss the bone growth abnormality achondroplasia (achondropla.docx
Please discuss the bone growth abnormality achondroplasia (achondropla.docx
 
Please answer all questions- Will upvote! Profitability ratios help in.docx
Please answer all questions- Will upvote! Profitability ratios help in.docxPlease answer all questions- Will upvote! Profitability ratios help in.docx
Please answer all questions- Will upvote! Profitability ratios help in.docx
 
picture of artery and vein to label i need a plain diagram of arteries.docx
picture of artery and vein to label i need a plain diagram of arteries.docxpicture of artery and vein to label i need a plain diagram of arteries.docx
picture of artery and vein to label i need a plain diagram of arteries.docx
 
Please answer all questions- 1) Adaptive immunity has five distinct a.docx
Please answer all questions-  1) Adaptive immunity has five distinct a.docxPlease answer all questions-  1) Adaptive immunity has five distinct a.docx
Please answer all questions- 1) Adaptive immunity has five distinct a.docx
 
Photoreceptors respond to the removal of light by Group of answer choi.docx
Photoreceptors respond to the removal of light by Group of answer choi.docxPhotoreceptors respond to the removal of light by Group of answer choi.docx
Photoreceptors respond to the removal of light by Group of answer choi.docx
 
Please answer all questions- IMMUNIZATION Immunization or vaccination.docx
Please answer all questions-  IMMUNIZATION Immunization or vaccination.docxPlease answer all questions-  IMMUNIZATION Immunization or vaccination.docx
Please answer all questions- IMMUNIZATION Immunization or vaccination.docx
 
Place these phases of an audit in chronological order- A- Assess the r.docx
Place these phases of an audit in chronological order- A- Assess the r.docxPlace these phases of an audit in chronological order- A- Assess the r.docx
Place these phases of an audit in chronological order- A- Assess the r.docx
 
Petty Cash Fund Petty Cash Fund Libby Company established a petty cas.docx
Petty Cash Fund  Petty Cash Fund Libby Company established a petty cas.docxPetty Cash Fund  Petty Cash Fund Libby Company established a petty cas.docx
Petty Cash Fund Petty Cash Fund Libby Company established a petty cas.docx
 
Please answer question 4b only 4- The image below (on Endomembrane Sys.docx
Please answer question 4b only 4- The image below (on Endomembrane Sys.docxPlease answer question 4b only 4- The image below (on Endomembrane Sys.docx
Please answer question 4b only 4- The image below (on Endomembrane Sys.docx
 
Please answer all questions- b- The in which CD95L binds to CD95 on t.docx
Please answer all questions-  b- The in which CD95L binds to CD95 on t.docxPlease answer all questions-  b- The in which CD95L binds to CD95 on t.docx
Please answer all questions- b- The in which CD95L binds to CD95 on t.docx
 
Please answer all questions- T Lymphocytes (T Cells) 1) T lymphocytes.docx
Please answer all questions-  T Lymphocytes (T Cells) 1) T lymphocytes.docxPlease answer all questions-  T Lymphocytes (T Cells) 1) T lymphocytes.docx
Please answer all questions- T Lymphocytes (T Cells) 1) T lymphocytes.docx
 
Please answer all questions- 5- When the inflammatory mediators excee (1).docx
Please answer all questions-  5- When the inflammatory mediators excee (1).docxPlease answer all questions-  5- When the inflammatory mediators excee (1).docx
Please answer all questions- 5- When the inflammatory mediators excee (1).docx
 
Please answer all questions- 10- Antibody Function- The binding of an.docx
Please answer all questions-  10- Antibody Function- The binding of an.docxPlease answer all questions-  10- Antibody Function- The binding of an.docx
Please answer all questions- 10- Antibody Function- The binding of an.docx
 
Phosphatidate is an intermediate in the formation of- a) phospholipids.docx
Phosphatidate is an intermediate in the formation of- a) phospholipids.docxPhosphatidate is an intermediate in the formation of- a) phospholipids.docx
Phosphatidate is an intermediate in the formation of- a) phospholipids.docx
 
phage type of 42D- Which statement(s) are true- Check All That Apply T.docx
phage type of 42D- Which statement(s) are true- Check All That Apply T.docxphage type of 42D- Which statement(s) are true- Check All That Apply T.docx
phage type of 42D- Which statement(s) are true- Check All That Apply T.docx
 
Pequired informetion Learning Objective 03-P6- Prepare closing entries.docx
Pequired informetion Learning Objective 03-P6- Prepare closing entries.docxPequired informetion Learning Objective 03-P6- Prepare closing entries.docx
Pequired informetion Learning Objective 03-P6- Prepare closing entries.docx
 
Please update the registers at the end of the program execution- Also.docx
Please update the registers at the end of the program execution- Also.docxPlease update the registers at the end of the program execution- Also.docx
Please update the registers at the end of the program execution- Also.docx
 
Please see below H10 table released by the Fed- Rates in currency unit.docx
Please see below H10 table released by the Fed- Rates in currency unit.docxPlease see below H10 table released by the Fed- Rates in currency unit.docx
Please see below H10 table released by the Fed- Rates in currency unit.docx
 
People are perceived as being more trustworthy when they- Select one-.docx
People are perceived as being more trustworthy when they- Select one-.docxPeople are perceived as being more trustworthy when they- Select one-.docx
People are perceived as being more trustworthy when they- Select one-.docx
 
Please make revision to the following program so it incorporates three.docx
Please make revision to the following program so it incorporates three.docxPlease make revision to the following program so it incorporates three.docx
Please make revision to the following program so it incorporates three.docx
 

Recently uploaded

Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonJericReyAuditor
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 

Recently uploaded (20)

Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lesson
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 

Please finish everything marked TODO BinaryNode-java public class Bi.docx

  • 1. Please finish everything marked TODO BinaryNode.java public class BinaryNode<E extends Comparable<E>> implements TreePrinter.PrintableNode{ private E data; private BinaryNode<E> left; private BinaryNode<E> right; private int height; private int size; private BinaryNode<E> parent; public BinaryNode(E data){ this.data = data; this.left = null; this.right = null; this.parent = null; this.height = 1; this.size = 1; } // TODO: Set up the BinaryNode public BinaryNode(E data, BinaryNode<E> left, BinaryNode<E> right, BinaryNode<E> parent){ } // Access fields E data() { return this.data; }; BinaryNode<E> left() { return this.left; } BinaryNode<E> right() { return this.right; } BinaryNode<E> parent() { return this.parent; } // Setter fields void setLeft(BinaryNode<E> left) { this.left = left; if(left != null) left.setParent(this); } void setRight(BinaryNode<E> right) { this.right = right; if(right != null) right.setParent(this); }
  • 2. void setParent(BinaryNode<E> parent) { this.parent = parent; } void setData(E data) { this.data = data; } void setHeight(int h){ this.height = h; } // Basic properties int height() { return this.height; } int size() { return this.size; } boolean isBalanced() { int leftHeight = (hasLeft()) ? left.height() : 0; int rightHeight = (hasRight()) ? right().height() : 0; return Math.abs(leftHeight - rightHeight) < 2; } boolean hasLeft(){ return left == null ? false : true; } boolean hasRight(){ return right == null ? false :true; } boolean hasParent(){ return parent == null ? false :true; } public boolean equals(BinaryNode<E> other){ if(other == null) return false; return other.data.equals(this.data); } // Can use these to help debug public TreePrinter.PrintableNode getLeft() { return left == null ? null : left; } public TreePrinter.PrintableNode getRight() { return right == null ? null : right; } public String getText() { return String.valueOf(data); } public String toString(){ String ret = ""; return "root " + this.data + " Left: " +(hasLeft() ? left.data : null) + " Right: " +(hasRight() ?
  • 3. right.data : null) + " parent: " + (hasParent() ? parent.data : null) ; } } BST.java import java.util.ArrayList; import java.util.Collection; import java.util.List; public class BST<E extends Comparable<E>> implements Tree<E> { private int height; private int size; private BinaryNode<E> root; public BST(){ this.root = null; this.height = 0; this.size = 0; } // TODO: BST public BST(BinaryNode<E> root){ } // Access field public BinaryNode<E> root() { return this.root; } // Basic properties public int height() { return this.height; } public int size() { return this.size; } public boolean isBalanced() { return root.isBalanced(); }
  • 4. // TODO: updateHeight - Update the root height to reflect any changes public void updateHeight() { } // Traversals that return lists // TODO: Preorder traversal public List<E> preOrderList() { return new ArrayList<>(); } // TODO: Inorder traversal public List<E> inOrderList() { return new ArrayList<>(); } // TODO: Postorder traversal public List<E> postOrderList() { return new ArrayList<>(); } // Helpers for BST/AVL methods // TODO: extractRightMost // This will be called on the left subtree and will get the maximum value. public BinaryNode<E> extractRightMost(BinaryNode<E> curNode) { return null; } // AVL & BST Search & insert same // TODO: search public BinaryNode<E> search(E elem) { return null; } // TODO: insert public void insert(E elem) { } // TODO: delete public BinaryNode<E> delete(E elem) { return null; } // Stuff to help you debug if you want // Can ignore or use to see if it works. static <E extends Comparable<E>> Tree<E> mkBST (Collection<E> elems) {
  • 5. Tree<E> result = new BST<>(); for (E e : elems) result.insert(e); return result; } public TreePrinter.PrintableNode getLeft() { return this.root.hasLeft() ? this.root.left() : null; } public TreePrinter.PrintableNode getRight() { return this.root.hasRight() ? this.root.right() : null; } public String getText() { return (this.root != null) ? this.root.getText() : ""; } }