Question: Write a function that takes as input a general tree and returns the number of nodes in that tree. Write your function to use the

Write a function that takes as input a general tree and returns the number of nodes in that tree. Write your function to use the GenTree and GTNode ADTs of Figure 6.2.

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

/** General tree ADT */ interface GenTree { public void clear(); public GTNode root (); // Clear the tree // 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.19 Rating (144 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Based on the provided image which shows an interface for a general tree ADT we can write a function that calculates the number of nodes in the tree Si... 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!