Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Students also viewed these Databases questions