SlideShare ist ein Scribd-Unternehmen logo
1 von 9
JAVA - Please complete the below method Ascii2Integer() USING RECURSION: I HAVE
ALSO INCLUDED THE LINKEDBTREE CLASS
/*
*/
import binarytree.*;
/**
A program that tests the ascii2int() method.
*/
public class Ascii2Integer
{
/**
A method that converts a binary tree of integer strings
into a binary tree of integers. This method assumes that
all of the strings in the input tree contain properly
formatted integers.
*/
public static LinkedBTree<Integer> ascii2int(BTree<String> btree)
{
}
// A simple test case for ascii2int().
public static void main(String[] args)
{
BTree<String> btree1 =
new LinkedBTree<>("1",
new LinkedBTree<>("12"),
new LinkedBTree<>("123"));
BTree<Integer> btree2 = ascii2int( btree1 );
System.out.println( btree1 );
BTree2dot.btree2dot(btree1, "btree1");
BTree2png.btree2png("btree1");
System.out.println( btree2 );
BTree2dot.btree2dot(btree2, "btree2");
BTree2png.btree2png("btree2");
}
}
package binarytree;
/**
This class defines a binary tree data structure
as an object that has a reference to a binary
tree node.
<p>
This class gives us a well defined empty binary tree
that is not represented by a null value. The empty
tree is internally denoted by a null reference, but
that reference is hidden inside of a {@code LinkedBTree}
object, so the null reference is not part of the public
interface. The internal reference to a node acts as a
"tag" (in a "tagged union") to distinguish between the
two cases of the binary tree algebraic data type.
<p>
See <a href="https://en.wikipedia.org/wiki/Tagged_union" target="_top">
https://en.wikipedia.org/wiki/Tagged_union</a>
<p>
Compared to the {@link BTreeLinked} implementation of the
{@link BTree} interface, this implementation "has a" node,
whereas {@link BTreeLinked} "is a" node.
<p>
The {@link binarytree.LinkedBTree.BTreeNode} data structure
is defines as a private, nested class inside of this
{@code LinkedBTree} class.
*/
public class LinkedBTree<T> extends BTreeA<T>
{
private BTreeNode<T> btreeNode;
/**
Construct an empty binary tree.
*/
public LinkedBTree()
{
btreeNode = null;
}
/**
Construct a leaf node.
Notice that if this constructor didn't exist, you could
still construct a leaf node, it would just be cumbersome.
For example,
<pre>{@code
BTree<String> leaf = new LinkedBTree<>("a", new LinkedBTree<>(), new LinkedBTree<>());
}</pre>
So this is really a "convenience" constructor. It doesn't
need to be defined, but it sure is convenient for it to be
here.
@param element reference to the data object to store in this node
@throws NullPointerException if {@code element} is {@code null}
*/
public LinkedBTree(T element)
{
if (null == element)
throw new NullPointerException("root element must not be null");
btreeNode = new BTreeNode<T>(element, null, null);
}
/**
Construct a BTree with the given binary trees
as its left and right branches.
@param element reference to the data object to store in this node
@param left left branch tree for this node
@param right right branch tree for this node
@throws NullPointerException if {@code element} is {@code null}
@throws NullPointerException if {@code left} is {@code null}
@throws NullPointerException if {@code right} is {@code null}
*/
public LinkedBTree(T element, LinkedBTree<T> left, LinkedBTree<T> right)
{
if (null == element)
throw new NullPointerException("root element must not be null");
if (null == left)
throw new NullPointerException("left branch must not be null");
if (null == right)
throw new NullPointerException("right branch must not be null");
// We need to "unwrap" the nodes from the left and right branches.
btreeNode = new BTreeNode<T>(element, left.btreeNode, right.btreeNode);
}
/**
This is a static factory method.
Convert an arbitrary {@link BTree} to a {@code LinkedBTree}.
@param <T> The element type for the {@link BTree}
@param btree A {@link BTree} of any type
@return a {@code LinkedBTree} version of the input tree
@throws NullPointerException if {@code btree} is {@code null}
*/
public static <T> LinkedBTree<T> convert(BTree<T> btree)
{
if (null == btree)
throw new NullPointerException("btree must not be null");
if ( btree.isEmpty() )
{
return new LinkedBTree<T>();
}
else if ( btree.isLeaf() ) // need this case for FullBTree
{
return new LinkedBTree<T>(btree.root(),
new LinkedBTree<T>(),
new LinkedBTree<T>());
}
else
{
return new LinkedBTree<T>(btree.root(),
convert (btree.left()),
convert (btree.right()));
}
}
// Implement the four methods of the BTree<T> interface.
@Override
public boolean isEmpty()
{
return null == btreeNode;
}
@Override
public T root()
{
if (null == btreeNode)
throw new java.util.NoSuchElementException("empty BTree");
return btreeNode.element;
}
@Override
public LinkedBTree<T> left()
{
if (null == btreeNode)
throw new java.util.NoSuchElementException("empty BTree");
// We need to "wrap" the node for the
// left branch in a BTree object.
LinkedBTree<T> temp = new LinkedBTree<T>();
temp.btreeNode = this.btreeNode.left;
return temp;
}
@Override
public LinkedBTree<T> right()
{
if (null == btreeNode)
throw new java.util.NoSuchElementException("empty BTree");
// We need to "wrap" the node for the
// right branch in a BTree object.
LinkedBTree<T> temp = new LinkedBTree<T>();
temp.btreeNode = this.btreeNode.right;
return temp;
}
// A private nested class definition.
private class BTreeNode<T>
{
public T element;
public BTreeNode<T> left;
public BTreeNode<T> right;
public BTreeNode(T data)
{
this(data, null, null);
}
public BTreeNode(T element, BTreeNode<T> left, BTreeNode<T> right)
{
this.element = element;
this.left = left;
this.right = right;
}
public String toString()
{
if (null == left && null == right)
{
return element.toString();
}
else
{
String result = "(" + element;
result += " ";
result += (null == left) ? "()" : left; // recursion
result += " ";
result += (null == right) ? "()" : right; // recursion
result += ")";
return result;
}
}
}//BTreeNode
}

Weitere ähnliche Inhalte

Ähnlich wie JAVA - Please complete the below method Ascii2Integer() USING RECURSIO.docx

Here is what I got so far, I dont know how to write union, interse.pdf
Here is what I got so far, I dont know how to write union, interse.pdfHere is what I got so far, I dont know how to write union, interse.pdf
Here is what I got so far, I dont know how to write union, interse.pdfarihantpatna
 
C++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docxC++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docxBrianGHiNewmanv
 
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
 
Create a JAVA program that performs file IO and database interaction.pdf
Create a JAVA program that performs file IO and database interaction.pdfCreate a JAVA program that performs file IO and database interaction.pdf
Create a JAVA program that performs file IO and database interaction.pdfmalavshah9013
 
BSTNode.Java Node class used for implementing the BST. .pdf
BSTNode.Java   Node class used for implementing the BST. .pdfBSTNode.Java   Node class used for implementing the BST. .pdf
BSTNode.Java Node class used for implementing the BST. .pdfinfo189835
 
Consider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docxConsider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docxmaxinesmith73660
 
Required to augment the authors Binary Search Tree (BST) code to .docx
Required to augment the authors Binary Search Tree (BST) code to .docxRequired to augment the authors Binary Search Tree (BST) code to .docx
Required to augment the authors Binary Search Tree (BST) code to .docxdebishakespeare
 
In this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdfIn this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdfcontact41
 
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfHow do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfmail931892
 
computer notes - Data Structures - 3
computer notes - Data Structures - 3computer notes - Data Structures - 3
computer notes - Data Structures - 3ecomputernotes
 
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
 
Please finish everything marked TODO BinaryNode-java public class Bi.docx
Please finish everything marked TODO   BinaryNode-java public class Bi.docxPlease finish everything marked TODO   BinaryNode-java public class Bi.docx
Please finish everything marked TODO BinaryNode-java public class Bi.docxJakeT2gGrayp
 
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
 
The following is to be written in JavaThe following is the BSTree.pdf
The following is to be written in JavaThe following is the BSTree.pdfThe following is to be written in JavaThe following is the BSTree.pdf
The following is to be written in JavaThe following is the BSTree.pdfeyewatchsystems
 
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...ssuserd6b1fd
 
Introduction to cpp (c++)
Introduction to cpp (c++)Introduction to cpp (c++)
Introduction to cpp (c++)Arun Umrao
 
Virtual Function and Polymorphism.ppt
Virtual Function and Polymorphism.pptVirtual Function and Polymorphism.ppt
Virtual Function and Polymorphism.pptishan743441
 
Using NetBeansImplement a queue named QueueLL using a Linked List .pdf
Using NetBeansImplement a queue named QueueLL using a Linked List .pdfUsing NetBeansImplement a queue named QueueLL using a Linked List .pdf
Using NetBeansImplement a queue named QueueLL using a Linked List .pdfsiennatimbok52331
 
maincpp Build and procees a sorted linked list of Patie.pdf
maincpp   Build and procees a sorted linked list of Patie.pdfmaincpp   Build and procees a sorted linked list of Patie.pdf
maincpp Build and procees a sorted linked list of Patie.pdfadityastores21
 
using the code below write the public V add(K key, V value); that ad.pdf
using the code below write the public V add(K key, V value); that ad.pdfusing the code below write the public V add(K key, V value); that ad.pdf
using the code below write the public V add(K key, V value); that ad.pdfamirthagiftsmadurai
 

Ähnlich wie JAVA - Please complete the below method Ascii2Integer() USING RECURSIO.docx (20)

Here is what I got so far, I dont know how to write union, interse.pdf
Here is what I got so far, I dont know how to write union, interse.pdfHere is what I got so far, I dont know how to write union, interse.pdf
Here is what I got so far, I dont know how to write union, interse.pdf
 
C++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docxC++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docx
 
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
 
Create a JAVA program that performs file IO and database interaction.pdf
Create a JAVA program that performs file IO and database interaction.pdfCreate a JAVA program that performs file IO and database interaction.pdf
Create a JAVA program that performs file IO and database interaction.pdf
 
BSTNode.Java Node class used for implementing the BST. .pdf
BSTNode.Java   Node class used for implementing the BST. .pdfBSTNode.Java   Node class used for implementing the BST. .pdf
BSTNode.Java Node class used for implementing the BST. .pdf
 
Consider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docxConsider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docx
 
Required to augment the authors Binary Search Tree (BST) code to .docx
Required to augment the authors Binary Search Tree (BST) code to .docxRequired to augment the authors Binary Search Tree (BST) code to .docx
Required to augment the authors Binary Search Tree (BST) code to .docx
 
In this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdfIn this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdf
 
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfHow do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
 
computer notes - Data Structures - 3
computer notes - Data Structures - 3computer notes - Data Structures - 3
computer notes - Data Structures - 3
 
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
 
Please finish everything marked TODO BinaryNode-java public class Bi.docx
Please finish everything marked TODO   BinaryNode-java public class Bi.docxPlease finish everything marked TODO   BinaryNode-java public class Bi.docx
Please finish everything marked TODO BinaryNode-java public class Bi.docx
 
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
 
The following is to be written in JavaThe following is the BSTree.pdf
The following is to be written in JavaThe following is the BSTree.pdfThe following is to be written in JavaThe following is the BSTree.pdf
The following is to be written in JavaThe following is the BSTree.pdf
 
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
 
Introduction to cpp (c++)
Introduction to cpp (c++)Introduction to cpp (c++)
Introduction to cpp (c++)
 
Virtual Function and Polymorphism.ppt
Virtual Function and Polymorphism.pptVirtual Function and Polymorphism.ppt
Virtual Function and Polymorphism.ppt
 
Using NetBeansImplement a queue named QueueLL using a Linked List .pdf
Using NetBeansImplement a queue named QueueLL using a Linked List .pdfUsing NetBeansImplement a queue named QueueLL using a Linked List .pdf
Using NetBeansImplement a queue named QueueLL using a Linked List .pdf
 
maincpp Build and procees a sorted linked list of Patie.pdf
maincpp   Build and procees a sorted linked list of Patie.pdfmaincpp   Build and procees a sorted linked list of Patie.pdf
maincpp Build and procees a sorted linked list of Patie.pdf
 
using the code below write the public V add(K key, V value); that ad.pdf
using the code below write the public V add(K key, V value); that ad.pdfusing the code below write the public V add(K key, V value); that ad.pdf
using the code below write the public V add(K key, V value); that ad.pdf
 

Mehr von lucilabevin

JKCorp- was listed in the US- sock marke- and isued lever 2 ADR- Whot.docx
JKCorp- was listed in the US- sock marke- and isued lever 2 ADR- Whot.docxJKCorp- was listed in the US- sock marke- and isued lever 2 ADR- Whot.docx
JKCorp- was listed in the US- sock marke- and isued lever 2 ADR- Whot.docxlucilabevin
 
Jeffrey has a company with 100 employees- Over the past quarter he has.docx
Jeffrey has a company with 100 employees- Over the past quarter he has.docxJeffrey has a company with 100 employees- Over the past quarter he has.docx
Jeffrey has a company with 100 employees- Over the past quarter he has.docxlucilabevin
 
JCL Inc- is a major chip manufacturing firm that sells its products to (3).docx
JCL Inc- is a major chip manufacturing firm that sells its products to (3).docxJCL Inc- is a major chip manufacturing firm that sells its products to (3).docx
JCL Inc- is a major chip manufacturing firm that sells its products to (3).docxlucilabevin
 
Java-Data structure Write a method that reverses the order of elemen.docx
Java-Data structure   Write a method that reverses the order of elemen.docxJava-Data structure   Write a method that reverses the order of elemen.docx
Java-Data structure Write a method that reverses the order of elemen.docxlucilabevin
 
JAVA please How do we implement a circular array Create an array of si.docx
JAVA please How do we implement a circular array Create an array of si.docxJAVA please How do we implement a circular array Create an array of si.docx
JAVA please How do we implement a circular array Create an array of si.docxlucilabevin
 
java Implement an algorithm to find the nth to the last element of a s.docx
java Implement an algorithm to find the nth to the last element of a s.docxjava Implement an algorithm to find the nth to the last element of a s.docx
java Implement an algorithm to find the nth to the last element of a s.docxlucilabevin
 
Jarrod became the father of triplets on June 20- On what date is he.docx
Jarrod became the father of triplets on June 20-   On what date is he.docxJarrod became the father of triplets on June 20-   On what date is he.docx
Jarrod became the father of triplets on June 20- On what date is he.docxlucilabevin
 
Janelle is a sixth-grade student who experiences hearing loss- When Ja.docx
Janelle is a sixth-grade student who experiences hearing loss- When Ja.docxJanelle is a sixth-grade student who experiences hearing loss- When Ja.docx
Janelle is a sixth-grade student who experiences hearing loss- When Ja.docxlucilabevin
 
Jane- who is married to Stuart- and Betty- a divorced single parent- h.docx
Jane- who is married to Stuart- and Betty- a divorced single parent- h.docxJane- who is married to Stuart- and Betty- a divorced single parent- h.docx
Jane- who is married to Stuart- and Betty- a divorced single parent- h.docxlucilabevin
 
It is the responsibility of the stakeholders to identify themselves to.docx
It is the responsibility of the stakeholders to identify themselves to.docxIt is the responsibility of the stakeholders to identify themselves to.docx
It is the responsibility of the stakeholders to identify themselves to.docxlucilabevin
 
Isabei Briggs Myers was a pioneer in the study of personality types- T.docx
Isabei Briggs Myers was a pioneer in the study of personality types- T.docxIsabei Briggs Myers was a pioneer in the study of personality types- T.docx
Isabei Briggs Myers was a pioneer in the study of personality types- T.docxlucilabevin
 
Issue Materiality is to Sustainability Materiality as Stakeholder Mana.docx
Issue Materiality is to Sustainability Materiality as Stakeholder Mana.docxIssue Materiality is to Sustainability Materiality as Stakeholder Mana.docx
Issue Materiality is to Sustainability Materiality as Stakeholder Mana.docxlucilabevin
 
Inflammatory bowel disease (IBD) is an autoimmune disorder impacting t.docx
Inflammatory bowel disease (IBD) is an autoimmune disorder impacting t.docxInflammatory bowel disease (IBD) is an autoimmune disorder impacting t.docx
Inflammatory bowel disease (IBD) is an autoimmune disorder impacting t.docxlucilabevin
 
is often used for interaction structure prediction)- Questions for Dis.docx
is often used for interaction structure prediction)- Questions for Dis.docxis often used for interaction structure prediction)- Questions for Dis.docx
is often used for interaction structure prediction)- Questions for Dis.docxlucilabevin
 
Ip Task- Study- mor rests e car for en ogroed pobiod oi The bemaked on.docx
Ip Task- Study- mor rests e car for en ogroed pobiod oi The bemaked on.docxIp Task- Study- mor rests e car for en ogroed pobiod oi The bemaked on.docx
Ip Task- Study- mor rests e car for en ogroed pobiod oi The bemaked on.docxlucilabevin
 
Introduction- Take this quiz to get a quick check on your understandin.docx
Introduction- Take this quiz to get a quick check on your understandin.docxIntroduction- Take this quiz to get a quick check on your understandin.docx
Introduction- Take this quiz to get a quick check on your understandin.docxlucilabevin
 
Introduction to Minerals and Rocks A large segment of geology is the s.docx
Introduction to Minerals and Rocks A large segment of geology is the s.docxIntroduction to Minerals and Rocks A large segment of geology is the s.docx
Introduction to Minerals and Rocks A large segment of geology is the s.docxlucilabevin
 
Introduction to Pest Biology Lab Manual- Try to complete this matching.docx
Introduction to Pest Biology Lab Manual- Try to complete this matching.docxIntroduction to Pest Biology Lab Manual- Try to complete this matching.docx
Introduction to Pest Biology Lab Manual- Try to complete this matching.docxlucilabevin
 
In which organisms a part of the genetic code has alternative reading-.docx
In which organisms a part of the genetic code has alternative reading-.docxIn which organisms a part of the genetic code has alternative reading-.docx
In which organisms a part of the genetic code has alternative reading-.docxlucilabevin
 
intermediate accounting II CH 14 Question 1- Early extinguishment of d.docx
intermediate accounting II CH 14 Question 1- Early extinguishment of d.docxintermediate accounting II CH 14 Question 1- Early extinguishment of d.docx
intermediate accounting II CH 14 Question 1- Early extinguishment of d.docxlucilabevin
 

Mehr von lucilabevin (20)

JKCorp- was listed in the US- sock marke- and isued lever 2 ADR- Whot.docx
JKCorp- was listed in the US- sock marke- and isued lever 2 ADR- Whot.docxJKCorp- was listed in the US- sock marke- and isued lever 2 ADR- Whot.docx
JKCorp- was listed in the US- sock marke- and isued lever 2 ADR- Whot.docx
 
Jeffrey has a company with 100 employees- Over the past quarter he has.docx
Jeffrey has a company with 100 employees- Over the past quarter he has.docxJeffrey has a company with 100 employees- Over the past quarter he has.docx
Jeffrey has a company with 100 employees- Over the past quarter he has.docx
 
JCL Inc- is a major chip manufacturing firm that sells its products to (3).docx
JCL Inc- is a major chip manufacturing firm that sells its products to (3).docxJCL Inc- is a major chip manufacturing firm that sells its products to (3).docx
JCL Inc- is a major chip manufacturing firm that sells its products to (3).docx
 
Java-Data structure Write a method that reverses the order of elemen.docx
Java-Data structure   Write a method that reverses the order of elemen.docxJava-Data structure   Write a method that reverses the order of elemen.docx
Java-Data structure Write a method that reverses the order of elemen.docx
 
JAVA please How do we implement a circular array Create an array of si.docx
JAVA please How do we implement a circular array Create an array of si.docxJAVA please How do we implement a circular array Create an array of si.docx
JAVA please How do we implement a circular array Create an array of si.docx
 
java Implement an algorithm to find the nth to the last element of a s.docx
java Implement an algorithm to find the nth to the last element of a s.docxjava Implement an algorithm to find the nth to the last element of a s.docx
java Implement an algorithm to find the nth to the last element of a s.docx
 
Jarrod became the father of triplets on June 20- On what date is he.docx
Jarrod became the father of triplets on June 20-   On what date is he.docxJarrod became the father of triplets on June 20-   On what date is he.docx
Jarrod became the father of triplets on June 20- On what date is he.docx
 
Janelle is a sixth-grade student who experiences hearing loss- When Ja.docx
Janelle is a sixth-grade student who experiences hearing loss- When Ja.docxJanelle is a sixth-grade student who experiences hearing loss- When Ja.docx
Janelle is a sixth-grade student who experiences hearing loss- When Ja.docx
 
Jane- who is married to Stuart- and Betty- a divorced single parent- h.docx
Jane- who is married to Stuart- and Betty- a divorced single parent- h.docxJane- who is married to Stuart- and Betty- a divorced single parent- h.docx
Jane- who is married to Stuart- and Betty- a divorced single parent- h.docx
 
It is the responsibility of the stakeholders to identify themselves to.docx
It is the responsibility of the stakeholders to identify themselves to.docxIt is the responsibility of the stakeholders to identify themselves to.docx
It is the responsibility of the stakeholders to identify themselves to.docx
 
Isabei Briggs Myers was a pioneer in the study of personality types- T.docx
Isabei Briggs Myers was a pioneer in the study of personality types- T.docxIsabei Briggs Myers was a pioneer in the study of personality types- T.docx
Isabei Briggs Myers was a pioneer in the study of personality types- T.docx
 
Issue Materiality is to Sustainability Materiality as Stakeholder Mana.docx
Issue Materiality is to Sustainability Materiality as Stakeholder Mana.docxIssue Materiality is to Sustainability Materiality as Stakeholder Mana.docx
Issue Materiality is to Sustainability Materiality as Stakeholder Mana.docx
 
Inflammatory bowel disease (IBD) is an autoimmune disorder impacting t.docx
Inflammatory bowel disease (IBD) is an autoimmune disorder impacting t.docxInflammatory bowel disease (IBD) is an autoimmune disorder impacting t.docx
Inflammatory bowel disease (IBD) is an autoimmune disorder impacting t.docx
 
is often used for interaction structure prediction)- Questions for Dis.docx
is often used for interaction structure prediction)- Questions for Dis.docxis often used for interaction structure prediction)- Questions for Dis.docx
is often used for interaction structure prediction)- Questions for Dis.docx
 
Ip Task- Study- mor rests e car for en ogroed pobiod oi The bemaked on.docx
Ip Task- Study- mor rests e car for en ogroed pobiod oi The bemaked on.docxIp Task- Study- mor rests e car for en ogroed pobiod oi The bemaked on.docx
Ip Task- Study- mor rests e car for en ogroed pobiod oi The bemaked on.docx
 
Introduction- Take this quiz to get a quick check on your understandin.docx
Introduction- Take this quiz to get a quick check on your understandin.docxIntroduction- Take this quiz to get a quick check on your understandin.docx
Introduction- Take this quiz to get a quick check on your understandin.docx
 
Introduction to Minerals and Rocks A large segment of geology is the s.docx
Introduction to Minerals and Rocks A large segment of geology is the s.docxIntroduction to Minerals and Rocks A large segment of geology is the s.docx
Introduction to Minerals and Rocks A large segment of geology is the s.docx
 
Introduction to Pest Biology Lab Manual- Try to complete this matching.docx
Introduction to Pest Biology Lab Manual- Try to complete this matching.docxIntroduction to Pest Biology Lab Manual- Try to complete this matching.docx
Introduction to Pest Biology Lab Manual- Try to complete this matching.docx
 
In which organisms a part of the genetic code has alternative reading-.docx
In which organisms a part of the genetic code has alternative reading-.docxIn which organisms a part of the genetic code has alternative reading-.docx
In which organisms a part of the genetic code has alternative reading-.docx
 
intermediate accounting II CH 14 Question 1- Early extinguishment of d.docx
intermediate accounting II CH 14 Question 1- Early extinguishment of d.docxintermediate accounting II CH 14 Question 1- Early extinguishment of d.docx
intermediate accounting II CH 14 Question 1- Early extinguishment of d.docx
 

Kürzlich hochgeladen

SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
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
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 

Kürzlich hochgeladen (20)

SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
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...
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 

JAVA - Please complete the below method Ascii2Integer() USING RECURSIO.docx

  • 1. JAVA - Please complete the below method Ascii2Integer() USING RECURSION: I HAVE ALSO INCLUDED THE LINKEDBTREE CLASS /* */ import binarytree.*; /** A program that tests the ascii2int() method. */ public class Ascii2Integer { /** A method that converts a binary tree of integer strings into a binary tree of integers. This method assumes that all of the strings in the input tree contain properly formatted integers. */ public static LinkedBTree<Integer> ascii2int(BTree<String> btree) { } // A simple test case for ascii2int(). public static void main(String[] args) { BTree<String> btree1 = new LinkedBTree<>("1", new LinkedBTree<>("12"), new LinkedBTree<>("123")); BTree<Integer> btree2 = ascii2int( btree1 ); System.out.println( btree1 ); BTree2dot.btree2dot(btree1, "btree1"); BTree2png.btree2png("btree1"); System.out.println( btree2 ); BTree2dot.btree2dot(btree2, "btree2"); BTree2png.btree2png("btree2"); } }
  • 2. package binarytree; /** This class defines a binary tree data structure as an object that has a reference to a binary tree node. <p> This class gives us a well defined empty binary tree that is not represented by a null value. The empty tree is internally denoted by a null reference, but that reference is hidden inside of a {@code LinkedBTree} object, so the null reference is not part of the public interface. The internal reference to a node acts as a "tag" (in a "tagged union") to distinguish between the two cases of the binary tree algebraic data type. <p> See <a href="https://en.wikipedia.org/wiki/Tagged_union" target="_top"> https://en.wikipedia.org/wiki/Tagged_union</a> <p> Compared to the {@link BTreeLinked} implementation of the {@link BTree} interface, this implementation "has a" node, whereas {@link BTreeLinked} "is a" node. <p> The {@link binarytree.LinkedBTree.BTreeNode} data structure
  • 3. is defines as a private, nested class inside of this {@code LinkedBTree} class. */ public class LinkedBTree<T> extends BTreeA<T> { private BTreeNode<T> btreeNode; /** Construct an empty binary tree. */ public LinkedBTree() { btreeNode = null; } /** Construct a leaf node. Notice that if this constructor didn't exist, you could still construct a leaf node, it would just be cumbersome. For example, <pre>{@code BTree<String> leaf = new LinkedBTree<>("a", new LinkedBTree<>(), new LinkedBTree<>()); }</pre> So this is really a "convenience" constructor. It doesn't need to be defined, but it sure is convenient for it to be
  • 4. here. @param element reference to the data object to store in this node @throws NullPointerException if {@code element} is {@code null} */ public LinkedBTree(T element) { if (null == element) throw new NullPointerException("root element must not be null"); btreeNode = new BTreeNode<T>(element, null, null); } /** Construct a BTree with the given binary trees as its left and right branches. @param element reference to the data object to store in this node @param left left branch tree for this node @param right right branch tree for this node @throws NullPointerException if {@code element} is {@code null} @throws NullPointerException if {@code left} is {@code null} @throws NullPointerException if {@code right} is {@code null} */ public LinkedBTree(T element, LinkedBTree<T> left, LinkedBTree<T> right) { if (null == element)
  • 5. throw new NullPointerException("root element must not be null"); if (null == left) throw new NullPointerException("left branch must not be null"); if (null == right) throw new NullPointerException("right branch must not be null"); // We need to "unwrap" the nodes from the left and right branches. btreeNode = new BTreeNode<T>(element, left.btreeNode, right.btreeNode); } /** This is a static factory method. Convert an arbitrary {@link BTree} to a {@code LinkedBTree}. @param <T> The element type for the {@link BTree} @param btree A {@link BTree} of any type @return a {@code LinkedBTree} version of the input tree @throws NullPointerException if {@code btree} is {@code null} */ public static <T> LinkedBTree<T> convert(BTree<T> btree) { if (null == btree) throw new NullPointerException("btree must not be null"); if ( btree.isEmpty() ) { return new LinkedBTree<T>();
  • 6. } else if ( btree.isLeaf() ) // need this case for FullBTree { return new LinkedBTree<T>(btree.root(), new LinkedBTree<T>(), new LinkedBTree<T>()); } else { return new LinkedBTree<T>(btree.root(), convert (btree.left()), convert (btree.right())); } } // Implement the four methods of the BTree<T> interface. @Override public boolean isEmpty() { return null == btreeNode; } @Override public T root() {
  • 7. if (null == btreeNode) throw new java.util.NoSuchElementException("empty BTree"); return btreeNode.element; } @Override public LinkedBTree<T> left() { if (null == btreeNode) throw new java.util.NoSuchElementException("empty BTree"); // We need to "wrap" the node for the // left branch in a BTree object. LinkedBTree<T> temp = new LinkedBTree<T>(); temp.btreeNode = this.btreeNode.left; return temp; } @Override public LinkedBTree<T> right() { if (null == btreeNode) throw new java.util.NoSuchElementException("empty BTree"); // We need to "wrap" the node for the // right branch in a BTree object. LinkedBTree<T> temp = new LinkedBTree<T>();
  • 8. temp.btreeNode = this.btreeNode.right; return temp; } // A private nested class definition. private class BTreeNode<T> { public T element; public BTreeNode<T> left; public BTreeNode<T> right; public BTreeNode(T data) { this(data, null, null); } public BTreeNode(T element, BTreeNode<T> left, BTreeNode<T> right) { this.element = element; this.left = left; this.right = right; } public String toString() { if (null == left && null == right) {
  • 9. return element.toString(); } else { String result = "(" + element; result += " "; result += (null == left) ? "()" : left; // recursion result += " "; result += (null == right) ? "()" : right; // recursion result += ")"; return result; } } }//BTreeNode }