@Test public void testFind() { assertNull(tree.find(40)); tree.add(20, "s"); tree.add(10, "c"); assertEquals("s", tree.find(20)); assertEquals("c", tree.find(10)); tree.add(30, "x"); assertEquals("x", tree.find(30)); }
@Override public V find(K key) { opsCount++; if (root==null){ return null; } else if (key.compareTo(root.key)==0){ return root.data; } else if (key.compareTo(root.key)<0){ return find(root.getLeft(),key); } else{ return find(root.getRight(),key); } }
AVLTreeImpl implements IAVLBinaryTree<K, V> { @Override public V find(K key) { opsCount++; if (root==null){ return null; } else if (key.compareTo(root.key)==0){ return root.data; } else if (key.compareTo(root.key)<0){ return find(root.getLeft(),key); } else{ return find(root.getRight(),key); } } }
AVLTreeImpl implements IAVLBinaryTree<K, V> { @Override public V find(K key) { opsCount++; if (root==null){ return null; } else if (key.compareTo(root.key)==0){ return root.data; } else if (key.compareTo(root.key)<0){ return find(root.getLeft(),key); } else{ return find(root.getRight(),key); } } AVLTreeImpl(boolean rotate); }
AVLTreeImpl implements IAVLBinaryTree<K, V> { @Override public V find(K key) { opsCount++; if (root==null){ return null; } else if (key.compareTo(root.key)==0){ return root.data; } else if (key.compareTo(root.key)<0){ return find(root.getLeft(),key); } else{ return find(root.getRight(),key); } } AVLTreeImpl(boolean rotate); void resetOpsCount(); int getOpsCount(); @Override boolean isEmpty(); @Override int size(); @Override void add(K key, V data); @Override boolean remove(K key); @Override K min(); @Override K max(); @Override int height(); @Override K root(); @Override BSTNode<K,V> getRootNode(); @Override V find(K key); @Override List<K> preorderTraversal(); @Override List<K> postorderTraversal(); @Override List<K> inorderTraversal(); @Override List<K> levelorderTraversal(); static void main(String[] args); }
AVLTreeImpl implements IAVLBinaryTree<K, V> { @Override public V find(K key) { opsCount++; if (root==null){ return null; } else if (key.compareTo(root.key)==0){ return root.data; } else if (key.compareTo(root.key)<0){ return find(root.getLeft(),key); } else{ return find(root.getRight(),key); } } AVLTreeImpl(boolean rotate); void resetOpsCount(); int getOpsCount(); @Override boolean isEmpty(); @Override int size(); @Override void add(K key, V data); @Override boolean remove(K key); @Override K min(); @Override K max(); @Override int height(); @Override K root(); @Override BSTNode<K,V> getRootNode(); @Override V find(K key); @Override List<K> preorderTraversal(); @Override List<K> postorderTraversal(); @Override List<K> inorderTraversal(); @Override List<K> levelorderTraversal(); static void main(String[] args);  }