Question: Write classes that implement the general tree class declarations of Figure 6.2 using the linked general tree implementation with child pointer arrays of Figure 6.12.

Write classes that implement the general tree class declarations of Figure 6.2 using the linked general tree implementation with child pointer arrays of Figure 6.12.

/** General tree ADT */ interface GenTree { public void clear (); // Clear the tree public GTNode root (); //

Your implementation must be able to support changes in the number of children for a node. When created, a node should be allocated with only enough space to store its initial set of children. Whenever a new child is added to a node such that the array overflows, allocate a new array from free store that can store twice as many children.

A R B Val Size R 2 F A 3 C D) (E (a) (b) Figure 6.12 A dynamic general tree representation with fixed-size

/** General tree ADT */ interface GenTree { public void clear(); // Clear the tree public GTNode root (); // Return the root // Make the tree have a new root, give first child and sib public void newroot (E value, GTNode first, GTNode sib); public void newleftchild (E value); // Add left child } Figure 6.2 The general tree node and general tree classes.

Step by Step Solution

3.33 Rating (153 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Heres a Java implementation of the general tree using lin... View full answer

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 Practical Introduction To Data Structures Questions!