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

Moved BSTRotation into BST

parent 9342fd45
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
package edu.bu.ec504.hw2;

import edu.bu.ec504.hw2.bst.BST;
import edu.bu.ec504.hw2.bst.BSTRotation;
import edu.bu.ec504.hw2.bst.BST.BSTRotation;
import java.util.ArrayList;
import java.util.Arrays;

+31 −0
Original line number Diff line number Diff line
@@ -7,6 +7,37 @@ package edu.bu.ec504.hw2.bst;
 */
public class BST<keyType extends Comparable<keyType> > {
    // SUBCLASSES
    /**
     * Represents one rotation (ZIG or ZAG) around one key in a Binary Search Tree
     */
    public static class BSTRotation {
        public enum RotationType {ZIG, ZAG}

        public BSTRotation(Integer myRotKey, RotationType myRotType) {
            rotKey = myRotKey;
            rotType = myRotType;
        }

        /**
         * @return A human-readable description of the rotation
         */
        public String toString() {
            StringBuilder result = new StringBuilder();
            switch (rotType) {
                case ZIG:
                    result.append("ZIG");
                    break;
                case ZAG:
                    result.append("ZAG");
                    break;
            }
            result.append(" on node ID ").append(rotKey);
            return result.toString();
        }

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

    /**
     * Represents the result of a {@link #extendedContains(Comparable)} call.
+0 −33
Original line number Diff line number Diff line
package edu.bu.ec504.hw2.bst;

/**
     * Represents one rotation (ZIG or ZAG) around one key in a Binary Search Tree
     */
    public class BSTRotation {
        public enum RotationType {ZIG, ZAG}

        public BSTRotation(Integer myRotKey, RotationType myRotType) {
            rotKey = myRotKey;
            rotType = myRotType;
        }

        /**
         * @return A human-readable description of the rotation
         */
        public String toString() {
            StringBuilder result = new StringBuilder();
            switch (rotType) {
                case ZIG:
                    result.append("ZIG");
                    break;
                case ZAG:
                    result.append("ZAG");
                    break;
            }
            result.append(" on node ID ").append(rotKey);
            return result.toString();
        }

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