Пример #1
0
 public static <TKey extends Comparable<TKey>, TValue> boolean isValid(
     BinarySearchST<TKey, TValue> bsst) {
   for (int i = 0; i < bsst.N; i++) {
     if (i < bsst.N - 1) if (bsst.keys[i].compareTo(bsst.keys[i + 1]) > 0) return false;
     if (i != bsst.rank(bsst.select(i))) return false;
   }
   return true;
 }
Пример #2
0
  /** @param args */
  public static void main(String[] args) {
    BinarySearchST<String, Double> st = new BinarySearchST<String, Double>();

    System.out.println(BinarySearchST.isValid(st));
    st.put("A+", 4.33);
    System.out.println(BinarySearchST.isValid(st));
    st.put("A", 4.00);
    System.out.println(BinarySearchST.isValid(st));
    st.put("A-", 3.67);
    System.out.println(BinarySearchST.isValid(st));
    st.put("B+", 3.33);
    System.out.println(BinarySearchST.isValid(st));
    st.put("B", 3.00);
    System.out.println(BinarySearchST.isValid(st));
    st.put("B-", 2.67);
    System.out.println(BinarySearchST.isValid(st));
    st.delete("B-");
    System.out.println(BinarySearchST.isValid(st));
    st.put("C+", 2.33);
    System.out.println(BinarySearchST.isValid(st));
    st.put("C", 2.00);
    System.out.println(BinarySearchST.isValid(st));
    st.delete("B-");
    System.out.println(BinarySearchST.isValid(st));
    st.put("C-", 1.67);
    System.out.println(BinarySearchST.isValid(st));
    st.put("D", 1.00);
    System.out.println(BinarySearchST.isValid(st));
    st.delete("A-");
    System.out.println(BinarySearchST.isValid(st));
    st.put("F", 0.00);

    System.out.println(BinarySearchST.isValid(st));
  }