@Test public void testSize() { assertEquals("Size of new tree not 0", 0, tree.size()); tree.add(20, "S"); assertEquals("Size after 1 insert wrong", 1, tree.size()); tree.remove(20); assertEquals("Size after last remove not 0", 0, tree.size()); for (int i = 0; i < 10 ; i++) { tree.add(i + i, "S"); } assertEquals("Size after multiple inserts wrong", 10, tree.size()); }
@Override public int size() { int size = 0; if (root==null){ return 0; } if (root.getLeft()==null && root.getRight()==null){ return 1; } if (root.getLeft()!=null){ size+= 1+size(root.getLeft()); } if (root.getRight()!=null){ size+= 1+size(root.getRight()); } return size; }
AVLTreeImpl implements IAVLBinaryTree<K, V> { @Override public int size() { int size = 0; if (root==null){ return 0; } if (root.getLeft()==null && root.getRight()==null){ return 1; } if (root.getLeft()!=null){ size+= 1+size(root.getLeft()); } if (root.getRight()!=null){ size+= 1+size(root.getRight()); } return size; } }
AVLTreeImpl implements IAVLBinaryTree<K, V> { @Override public int size() { int size = 0; if (root==null){ return 0; } if (root.getLeft()==null && root.getRight()==null){ return 1; } if (root.getLeft()!=null){ size+= 1+size(root.getLeft()); } if (root.getRight()!=null){ size+= 1+size(root.getRight()); } return size; } AVLTreeImpl(boolean rotate); }
AVLTreeImpl implements IAVLBinaryTree<K, V> { @Override public int size() { int size = 0; if (root==null){ return 0; } if (root.getLeft()==null && root.getRight()==null){ return 1; } if (root.getLeft()!=null){ size+= 1+size(root.getLeft()); } if (root.getRight()!=null){ size+= 1+size(root.getRight()); } return size; } 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 int size() { int size = 0; if (root==null){ return 0; } if (root.getLeft()==null && root.getRight()==null){ return 1; } if (root.getLeft()!=null){ size+= 1+size(root.getLeft()); } if (root.getRight()!=null){ size+= 1+size(root.getRight()); } return size; } 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);  }