private Object sortOutput(Comparable data, Comparable count)
{
alphaRoot = insert(alphaRoot, data, count);
}
private Object sortOutput(alphaNode n, Comparable data, Comparable count)
{
if(n == null)
{
return new alphaNode(data, count);
}
else
{
//if the count is larger than the current nodes count swap
if(count.compareTo(n.count)>= 0)
{
Comparable temp = data;
data = n.data;
n.data = temp;
}
//if there is no left child move left and call recursivly
if(n.left == null)
{
n.left = sortOutput(n.left, data, count);
}
//if there is no right child move right and call recursivly
else if(n.right == null)
{
n.right = sortOutput(n.right, data, count);
}
else
{
//If the left side is larger than the right side move left; else move right
if(n.left.size <= n.right.size)
n.left = sortOutput(n.left, data, count);
else
n.right = sortOutput(n.right, data, count);
}
}
//increment size counter and return n
n.size++;
return n;