コード例 #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
ファイル: SplayTreeTest.java プロジェクト: jsirvine/SplayTree
 @Test
 public void testIsLeftChild() {
   assertFalse(SplayTree.isLeftChild(tree.getRoot()));
   assertFalse(SplayTree.isLeftChild(tree.getRoot().right));
   assertFalse(SplayTree.isLeftChild(tree.getRoot().left));
   SplayTree.Node root = tree.getRoot();
   SplayTree.Node node = tree.new Node();
   root.left = node;
   node.parent = root;
   assertTrue(SplayTree.isLeftChild(node));
 }
コード例 #3
0
ファイル: SplayTreeTest.java プロジェクト: jsirvine/SplayTree
 @Test
 public void testConstructor() {
   SplayTree.Node root = tree.getRoot();
   int nodes = 0;
   SplayTree.Node maxNode = root;
   while (maxNode != null) {
     if (maxNode != root) {
       assertEquals(maxNode.val, maxNode.parent.val + 1);
     } else {
       assertEquals(0, maxNode.val);
     }
     nodes++;
     maxNode = maxNode.right;
   }
   assertEquals(4, nodes);
 }
コード例 #4
0
 @Override
 public Word get(Word word) {
   // TODO Auto-generated method stub
   return (Word) splayTree.find(word);
 }
コード例 #5
0
 public void add(Word wordObject) {
   splayTree.insert(wordObject);
 }