Write a recursive method which takes the reference to the


My question is regarding Problem 4.33 (page 164) of the textbook Data Structures and Algorithm Analysis in Java (3rd Edition).

"Write a recursive method which takes the reference to the root node of a tree T and returns a reference to the root node of the tree that results from removing all leaves from T."

How Node is being constructed

class Node {

int data;

Node left, right;

/*

* Constructs a leaf

*/

Node(int key) {

this(key, null, null);

}

/*

* Constructs a Node

*/

Node(int data, Node left, Node right) {

this.data = data;

this.left = left;

this.right = right;

}

 

/*

* Checks to see if node is a Leaf

*/

 

boolean isLeaf() {

return left == null && right == null;

}

}

//pre-defined

Node root;

int n;

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: Write a recursive method which takes the reference to the
Reference No:- TGS02910884

Expected delivery within 24 Hours