private void sort(int[] tree) {
    for(boolean found=true; found==true;) {
      found = false;
//      printme(tree);
      
      for(int i=1; !found && i<tree.length; i++) {
        if(tree[i-1]>tree[i]){
          found = true;
          swap(tree, i-1, i);
        }
      }
      
      for(int i=tree.length-2; !found && i>=0;i--) {
        if(tree[i]==tree[i+1] && compare(tree,i,i+1)>0) {
          found = true;
          swap(tree, i, i+1);
        }
      }      
    }
	}