Algorithm getkeyTofind Declare a variable of type MapEnt nam

Algorithm get(keyTofind) Declare a variable of type MapEnt named elem Set elem equal to a new MapEnt with keyToFind as its key and null as its value if elem is in bst Declare a variable of type BTNode named node Set node equal to calling getBTNode(elem) from bst Set elem equal to node\'s element Return elem.getValue() else Return null end if end Algorithm put(keyToAdd, valueToAdd) Declare a variable of type MapEnt named newElem Set newElem equal to a new MapEnt with keyToAdd as its key and valueToAdd as its value if newElem is in bst Declare a variable of type BTNode named node Set node equal to getBTNode(newElem) from bst Declare a variable of type MapEnt named oldElem Set oldElem equal to node\'s element Declare a variable of type String named retVal Set retVal equal to oldElem-s value Set nodes element to newElem Return retVal else Add neWElem to bst Return null endif end

Solution

Code for PUT algorithm:

   //This class is to implement bst .
   public class bst {
  
   //Method to put value into root.
public boolean put(int value) {
       //Checking
if (root == null) {
root = new bstnode(value);
return true;
} else
return root.put(value);
}
   }
   public class bstnode {
//client class
public boolean put(int value) {
               //checking value
               if (value == this.value)
return false;
                   else if (value <this.value) {
                   if (left == null) {
left = new bstnode(value);
return true;
} else
return left.put(value);
} else if (value > this.value) {
if (right == null) {
right = new bstnode(value);
return true;
} else
return right.put(value);
}
return false;
}
}

CODE for get Method:

public class bst {
  
public boolean get(int value) {
if (root == null)
return false;
else
return root.get(value);
}
}

public class bstnode {

public boolean get(int value) {
if (value == this.value)
return true;
else if (value < this.value) {
if (left == null)
return false;
else
return left.get(value);
} else if (value > this.value) {
if (right == null)
return false;
else
return right.get(value);
}
return false;
}
}

 Algorithm get(keyTofind) Declare a variable of type MapEnt named elem Set elem equal to a new MapEnt with keyToFind as its key and null as its value if elem is
 Algorithm get(keyTofind) Declare a variable of type MapEnt named elem Set elem equal to a new MapEnt with keyToFind as its key and null as its value if elem is

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site