/**simple implementation of an m-way B tree*/ public class BTree> { private BNode root; private int capacity; //number of elements at each node public BTree(int m){ root=null; capacity=m-1; System.out.println("Creating new tree with capacity " + capacity+ "\n"); } public int getCapacity(){ return capacity; } public BNode getRoot() { return root; } public void setRoot(BNode r) { this.root = r; } public boolean isEmpty(){ return (root==null); } public static boolean isEmpty(BNode p){ return (p==null); } /**insert node containing element e if doesn't already exist * starting at node p * @return root */ public BCluster insert(E e, BNode p){ BCluster myBCluster=new BCluster(); int m=capacity+1; if(p==null) {BNode pNew=new BNode(e,this.getCapacity()+1); myBCluster=new BCluster(pNew,null,null); } else{ if(p.isLeaf()){ if (p.getSize()(p,null,null); } else myBCluster=p.divideNode(e,null,null); } else{ if (p.getSeq()[0].getVal().compareTo(e)>0) myBCluster=new BCluster(insert(e,p.getLeft())); else{ int temp=0; while ((temp0)){ myBCluster=new BCluster(insert(e,p.getSeq()[temp-1].getRight())); } } if(myBCluster.getP2()!=null){//a value has been sent back up // System.out.println("The value " + myBCluster.getValue()+" has been returned"); if(p.getSize()(p,null,null); } else myBCluster=p.divideNode(myBCluster.getValue(),myBCluster.getP1(), myBCluster.getP2()); } } } return myBCluster; } /**insert node containing e if doesnt already exist, starting at root*/ public void insert(E e){ System.out.println("Inserting value " +e); int m=capacity+1; if (isEmpty()) setRoot(new BNode(e,m)); else{ BCluster newBCluster = new BCluster(insert(e, root)); if(newBCluster.getP2()!=null){ //System.out.println("Moving root up! To contain " + newBCluster.getValue()); //System.out.println("will point to nodes "+ newBCluster.getP1() + " and " + newBCluster.getP2()); root=new BNode(newBCluster.getValue(),m); root.setLeft(newBCluster.getP1()); root.getSeq()[0].setRight(newBCluster.getP2()); } } } /**see if tree contains value e * starting at node p*/ public boolean contains(E e, BNode p){ if(p==null) return false; else{ if (p.getSeq()[0].getVal().compareTo(e)>0) return contains(e,p.getLeft()); else{ int i=0; while((i p){ String s=""; if (p!=null) { s=s+toString(p.getLeft()); int i=0; while(i p){ int size=0; if (p!=null){ size=getSize(p.getLeft()); int i=0; while(i p){ String s=""; if (p!=null){ s=s+p.toString()+outputNodes(p.getLeft()); int i=0; while(i