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

An Euler traversal of a BinaryTree processes a node, then if there is a left sub

ID: 3791988 • Letter: A

Question

An Euler traversal of a BinaryTree processes a node, then if there is a left subtree of the node, it processes that left subtree and processes the node again, finally if there is a right subtree of the node, it processes that right subtree and processes the node yet again. Assume that Binary Trees are implemented as in class, based on the following skeleton Java code: class BNode extends Node {BNode left, right;//The inherited instance variables from class Node are: parent and data//standard methods and constructors omitted} class Binary Tree extends Tree {//The inherited instance variable from class Tree is: Node root//standard methods and constructors omitted} Suppose that the class BinaryTree includes the method: public Vector eulerOrder() {Vector answer = new Vector (); if (root! = null) eulerOrder (BNode) roots answer); return answer;} Write a Java implementation for the auxiliary recursive method called eulerOrder.

Explanation / Answer

public abstact class eulto<E,R>{

{

protected bintree<E> tree;

public abstartct R execute(bintree<E> t);

protected void init(bintree<E> T) { tree =T ; }

protected R eulto(Position<E> v) {

Tourresult<R> r = new Tourresult<R>();

visitLeft(v,r);

if(tree.hasLeft(v))

r.left = eulto(tree.left(v));

visitbelo(v,r);

if(tree.hasRight(v))

r.right=eulto(tree.right(v));

visitright(v,r);

return r.out;

}

protected void visitleft(position<E> v,TourResult<r> r){ }

protected void visitlright(position<E> v,TourResult<r> r){ }

protected void visitbelow(position<E> v,TourResult<r> r){ }

public class tourresult<r>

{

public r left;

public r right;

public r out;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote