Question: Implement the IntTree class shown on the following slides. I will give you a test driver. The drive will expect one command line argument. The

Implement the IntTree class shown on the following slides. I will give you a test driver. The drive will expect one command line argument. The argument will be the name of a text file. import java.io.*; import java.util.*;

public class IntTree {

Homework 4

private class Node { private int data; private Node firstChild; private Node sibling; private Node parent;

private Node (int d, Node f, Node s, Node p) { data = d;

firstChild = f; sibling = s; parent = p;

} }

private Node root;

public IntTree(int d) { //create a one node tree

}

public IntTree(IntTree t[], int d) { //create a new tree whose children are the trees in t and whose root value is d

}

public IntTree(int d[]) { //create a tree with d[0] as the root value and the other values as children of the root

}

public String preorder() { //return a string of the ints in the tree in preorder //separate the ints with commas //the implementation must be recursive

}

public String postorder() { //return a string of the ints in the tree in postorder //separate the ints with commas //the implementation must be recursive

}

public String levelorder() { //return a string of the ints in the tree in level order (also know a breadth first order) //separate the ints with commas

//the implementation must be iterative

}

public String path(int d) { //return the ints in the path from the first occurrence of d in the tree to the root of the tree //the first occurrence means the first occurrence found in a preorder traversal //the implementation must use the parent reference to create the path //separate the ints with commas //the implementation must be iterative

}

public int count(int d) { //return the number of times d appears in the tree //the implementation must be recursive

}

public int sum() { //return the sum of the ints in the tree //the implementation must be iterative

} }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!