Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

/** Color every node on the path from the root node to the minimum value in the

ID: 3838037 • Letter: #

Question


/** Color every node on the path from the root node to the minimum value in the
   * tree with the given color
   * @return the element with the smallest key, or null, if there is no such element
I wrote the first method but it is not coloring every node along the path to the minimum value.
   */
public E first ( Color theColor )
   {
       BSTElement<K, E> curr = root;
       if ( root == null)
           return null;
       boolean found = false;

       while ( curr != null && ! found ) {

           curr.getVisualizer().setColor( theColor ); // color each node on the search path

               // we found the minimum value
       if (curr.getLeft() == null){
          
               curr.getLeft();
               curr.getVisualizer().setColor(theColor); // color
               return curr.getValue();
      
       }
      
   }
       return null;
   }


public int countAndColorMajors ( Color theColor, String theMajor )
{

//* This method traverses the enitre tree. This method traverses the entire tree. Each node is examined, and if the value
stored at that node is a Student object, and if the major field of that Student object
equals the parameter theMajor, then that node is set to the specified color c. The
total number of nodes that are colored by this method is returned. Note that this is
the only method in this assignment that assumes that the data stored in the tree are
Student objects. Your code can always check whether a value stored in the tree is
a Students object using the instanceof operator in Java. For example:
if ( foo instanceof Student ) { .... }            / I need help with this method//

   return -1;
           }  


          
public void colorRange ( Color theColor, K minValue, K maxValue ) {

/** set the color of every node that is greater-than-or-equal-to minValue
           * but less-than maxValue to be the given color
           */

           }

public void deleteSmall ( K key )
           {

/** Remove from the tree every node that is less-than-or-equal-to than the given key . To remove these keys you should directly alter the pointers in the tree using setLeft and setRight methods to splice out the small values*/


}
           }

Explanation / Answer

public E first ( Color theColor )
   {
       BSTElement<K, E> curr = root;
       if ( root == null)
           return null;
       boolean found = false;

       while ( curr != null && ! found ) {

           curr.getVisualizer().setColor( theColor );


       if (curr.getLeft() == null){
          
               curr.getLeft();
               curr.getVisualizer().setColor(theColor);
               return curr.getValue();
      
  }
      
   }
       return null;
   }

public int countAndColorMajors ( Color theColor, String theMajor )
{

if ( foo instanceof Student )

return -1;
           }  

public void colorRange ( Color theColor, K minValue, K maxValue ) {

}

public void deleteSmall ( K key )
{

}
}