BinaryTree class
$30-250 USD
Pagado a la entrega
Add the following methods to the class BinaryTree shown below:
public T get(int i)
public void add(int i, T element)
public T remove(int i)
All these methods use the inorder traversal of the tree. Feel free to use
helper methods and/or extra fields.
Here are the description of what the methods do.
---------------------------------------------------------------------------------
get(i) returns the element of the i-th node of the inorder traversal of the tree.
If i is outside the range it throws a NOSuchElementException.
For example if the inorder traversal of the tree t is
a, b, c, d, e, f, g, h, i, j, k
[login to view URL](4) returns e.
----------------------------------------------------------------------------------
public void add(int i, T element)
inserts element in the tree such that it is the i-th item in the inorder traversal.
Throw an index out of bounds exception if i is out of bounds and increase size
if the insertion is successful.
For example if the inorder traversal of the tree t is
a, b, c, d, e, f, g, h, i, j, k
after the call [login to view URL](5, x);
the inorder traversal of t is
a, b, c, d, e, x, f, g, h, i, j, k
-----------------------------------------------------------------------------------
public T remove(int i)
removes the i-th item of the tree.
Throw a no such element exception if i is out of range.
Don't forget to decrease the size if the remove is successful.
For example if the inorder traversal of the tree t is
a, b, c, d, e, f, g, h, i, j, k
the call [login to view URL](5);
returns f and the inorder traversal of t is
a, b, c, d, e, g, h, i, j, k
--------------------------------------------------------------------------------------
Here is the class [login to view URL]
import [login to view URL];
public class BinaryTree<T> {
/** Creates an empty binary tree */
public BinaryTree()
{
root = null;
}
// create a binary tree with a given root value
public BinaryTree( T rootItem)
{
root = new BinaryNode( rootItem, null, null);
size = 1;
}
// @return the root of the tree
public BinaryNode<T> getRoot()
{
return root;
}
// @return the size of the tree
public int size()
{
return size;
}
// @return the the height of the tree
public int height()
{
return [login to view URL](root);
}
// print the tree in preorder
public void printPreOrder()
{
if (root != null)
[login to view URL]();
}
// print the tree in postorder
public void printPostOrder()
{
if (root != null)
[login to view URL]();
}
// print the tree in inorder
public void printInOrder()
{
if (root != null)
[login to view URL]();
}
// empty the tree
public void makeEmpty()
{
root = null;
size = 0;
}
// check if the tree is empty
public boolean isEmpty()
{
return root == null;
}
// forms a new tree from rootItem t1 and t2
// does not allow t1 and t2 to be the same
public void merge(T rootItem, BinaryTree<T> t1, BinaryTree<T> t2)
{
if ([login to view URL] == [login to view URL] && [login to view URL] != null)
throw new IllegalArgumentException();
// allocate new node
root = new BinaryNode<T>(rootItem, [login to view URL], [login to view URL]);
size = [login to view URL]() + [login to view URL]() + 1;
// ensures that every node is in one tree
if (this != t1)
[login to view URL] = null;
if ( this != t2)
[login to view URL] = null;
}
private BinaryNode<T> root;
private int size = 0;
}
Nº del proyecto: #6731107
Sobre el proyecto
Adjudicado a:
Hi, I will be able to do this in a day time. Please let me know if you would like me to assist you with this project. We have already done two projects on the same lines. So I would be happy to continue the relation Más
18 freelancers están ofertando un promedio de $49 por este trabajo
HI Contact me for an efficient, perfect, well documented development of your project according to 100% accuracy and requirements, with dedicated support. Thanks Farah Saif
Hello. I am experienced with Java and I am familiar with Binary Tree data structure very well. It can be done in few hours.
Dear sir. I've scrutinized your project description. Because I have mastered "Data structure and Algorithm", I can surely do this very quickly and cleanly. Choose me to have the best one.
Hello, I am Java expert. I am willing to help you do this project right now. Please contact me. Thank you
Hello, I have 6 years experience in java. I can do this assignment. Please message me for further discussion.
I can do this project, choose me, please :) ..................................................................
hey buddy contact me and I will complete this in less than one hour...you can see my profile my speed and quality for any work is very great
I have read and understand your requirements Please open chat window to discuss further.. ++++++++++++++++++++========================+++++++++++++++++++++++++++++++++++++++++
Hello There I am 5 year Java Experienced I will do it for you in very short time , will also add comments if you want to code Thank in advance Hiasat
This project is easy. I can make it with clean code, understanding comment :) If you need explanation, I can hold a quick talk via skype if needed (but I got a flu now, please wait for 1-2 days).
Dear sir, if you would like to hire me, let me know. I am engineering undergraduate of University of Moratuwa, Sri Lanka. I will support you in my best. Thanks in advance.
We are the leading young professional software development organization having extensive technical expertise and knowledge in developing, managing, optimizing and customizing software’s by implementing these software’s Más