Question: I'm having problems trying to make the insert part work in my code. I'm allowed to have //private Node mRoot; in my BST constructor. The

I'm having problems trying to make the insert part work in my code. I'm allowed to have //private Node mRoot; in my BST constructor. The Node is a private class in BST.

public class BST { private Node mRoot; public BST() { Node mRoot = new Node (""); } public void insert(String key) { Node newNode = new Node(key); if(key.compareTo(mData)

private class Node { public Node(String data) { mData = data; mParent = null; mLeft = mRight = null; } private String mData; private Node mParent; private Node mLeft; private Node mRight; } }

I'm having problems trying to make the insert part work in my

2 public class BST private de mRoot; No 6e public BST Node mRoot new Node 10 11e public void insert (String key) 12 de ne de new Node (key) 13 14 A15 if (key.com To (Data) (0) pare 16 A17 if(mLeft null) 18 0019 mLeft null) A20 wNode this; Paren ne 21 return; 22 else 23 24 mLeft. insert (key) A25 26 27 else 28 29 A30 if (mRight null) 31 mRight null) A33 wNode this; Paren ne 34 return; 35 else 36 37 A38 mRight insert (key) 39 41 42 430 private class Node public Node (String data) Data data Paren null Left mRigh null 50 51 private String mData; 52 private de Paren No 53 private No mLeft; de 54 private de Right No 55 56

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!