BinaryTree class

Completado Publicado Nov 14, 2014 Pagado a la entrega
Completado 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;

}

Java

Nº del proyecto: #6731107

Sobre el proyecto

18 propuestas Proyecto remoto Activo Nov 14, 2014

Adjudicado a:

dharamdaring

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

$50 USD en 1 día
(17 comentarios)
4.3

18 freelancers están ofertando un promedio de $49 por este trabajo

it2051229

Hi, I am placing my bid on your project because I have read the requirements and I am confident enough with my Java and algorithm skills. I am focused mostly on doing computer science work here in freelancer.com and I Más

$30 USD en 1 día
(1093 comentarios)
7.7
urmate

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

$30 USD en 1 día
(514 comentarios)
7.4
vano101

Hello. I am experienced with Java and I am familiar with Binary Tree data structure very well. It can be done in few hours.

$30 USD en 1 día
(637 comentarios)
6.9
zhengnami13

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.

$210 USD en 3 días
(13 comentarios)
6.8
hbxfnzwpf

I am very proficient in java. I have 12 years java developing experience. I have worked for 5 years, my work is online game developing, and mainly focus on server side, the language is java under linux, I am proficint Más

$30 USD en 1 día
(88 comentarios)
6.5
vita1ity

Hello. I am interested in your project. I have required skills and experience in Java development including working with data structures. I have completed several projects on this freelancer site and on others resource Más

$30 USD en 1 día
(37 comentarios)
5.8
manhpham

Hello, I am Java expert. I am willing to help you do this project right now. Please contact me. Thank you

$55 USD en 1 día
(53 comentarios)
5.5
dipakjadhav08

Hello, I have 6 years experience in java. I can do this assignment. Please message me for further discussion.

$30 USD en 2 días
(103 comentarios)
5.5
sunary

I can do this project, choose me, please :) ..................................................................

$30 USD en 3 días
(7 comentarios)
5.0
apacherai

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

$100 USD en 3 días
(13 comentarios)
3.4
cscinstructor

I have read and understand your requirements Please open chat window to discuss further.. ++++++++++++++++++++========================+++++++++++++++++++++++++++++++++++++++++

$30 USD en 1 día
(8 comentarios)
3.7
Hiasat

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

$30 USD en 1 día
(12 comentarios)
3.2
KathrynFMurphy

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).

$55 USD en 3 días
(4 comentarios)
2.1
yamal90

Hi sir :)) , i'm a 3 years contestant in ACM ( algorithms and programming contest ) , them i became a coach and judge in the national version , i'm really good in algorithms and java programming , please consider mu bi Más

$30 USD en 0 días
(0 comentarios)
0.0
VshlKash

A proposal has not yet been provided

$35 USD en 2 días
(0 comentarios)
0.0
clrajapaksha

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.

$30 USD en 1 día
(0 comentarios)
0.0
KhalidShah123

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

$44 USD en 3 días
(0 comentarios)
0.0