コード例 #1
0
  public static void main(String[] args) {
    SplayTree myNameIsSonyAndICantProgram =
        new SplayTree(); // We won't be using this, I just felt it was necessary.
    SplayTree splay = new SplayTree();

    // Randomly creates a SplayTree, printing out the Tree after each insert
    int rand = (int) (Math.random() * 25 + .5);
    for (int i = 0; i < rand; i++) {
      int temp = (int) (Math.random() * 100 + .5);
      System.out.println("Attempting to add " + temp + " to the SplayTree:\nNew SplayTree:");
      splay.insert(temp);
      print(splay.getRoot());
    }

    // Removes all of the data by the root
    while (splay.getSize() > 0) {
      if (splay.getRoot() != null) {
        System.out.println(
            "Attempting to remove "
                + splay.getRoot().getValue()
                + " from the tree.\nNew SplayTree:");
        splay.remove(splay.getRoot().getValue());
        print(splay.getRoot());
      } else break;
    }
  }
コード例 #2
0
 public void add(Word wordObject) {
   splayTree.insert(wordObject);
 }