Commit b8333115 authored by Ari Trachtenberg's avatar Ari Trachtenberg
Browse files

parameterized BSTRotation by keyType (hattip Bowen Qin)

parent 629b4c57
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ class Main {
        intResult = intTest.extendedContains(6);
        System.out.println("... 6 is in your BST? " + intResult.getSearchResult()+" in "+intResult.getSearchCount()+" steps;\n "+intResult.getLastSeen());
        System.out.println("Your string BST is:\n"+strTest);
        System.out.println("One rotation: "+new BSTRotation(3, BSTRotation.RotationType.ZAG));
        System.out.println("One rotation: "+ new BSTRotation<>(3, BSTRotation.RotationType.ZAG));

    }
}
+5 −5
Original line number Diff line number Diff line
@@ -10,10 +10,10 @@ public class BST<keyType extends Comparable<keyType> > {
    /**
     * Represents one rotation (ZIG or ZAG) around one key in a Binary Search Tree
     */
    public static class BSTRotation {
    public static class BSTRotation<keyType> {
        public enum RotationType {ZIG, ZAG}

        public BSTRotation(Integer myRotKey, RotationType myRotType) {
        public BSTRotation(keyType myRotKey, RotationType myRotType) {
            rotKey = myRotKey;
            rotType = myRotType;
        }
@@ -36,10 +36,10 @@ public class BST<keyType extends Comparable<keyType> > {
        }

        // getters
        Integer getRotKey() { return rotKey; }
        keyType getRotKey() { return rotKey; }
        RotationType getRotType() { return rotType; }

        private final Integer rotKey;            // the key of the root of the rotation being performed
        private final keyType rotKey;            // the key of the root of the rotation being performed
        private final RotationType rotType;      // the type of rotation being performed
    }

@@ -194,7 +194,7 @@ public class BST<keyType extends Comparable<keyType> > {
     * Inserts the new number as a key into the binary search tree
     *
     * @param newKey The new key to be inserted.
     * @return
     * @return true if the key was successfully inserted into the tree
     */
    public boolean add(keyType newKey) {
        searchRecord theRecord = searchHelper(newKey);
+1 −1
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ public class ExtendedBSTSet<keyType extends Comparable<keyType>> extends BSTSet<
   * @param op A rotational operation to complete.
   * @return true iff the rotation was successful.
   */
  public boolean rotate(BSTRotation op) {
  public boolean rotate(BSTRotation<keyType> op) {
    return false;
  }