Beruflich Dokumente
Kultur Dokumente
*;
TwoThreeTree()
{
root = null;
traverse = new Traversal();
size = 0;
}
void insert(T x)
{
if (root == null) // If root is null, then create a new root with null as the parent
{
root = new Node(x);
size++;
}
root.insert(x); // Otherwise induce a recursive insert.
modified = true;
}
int size()
{
return size;
}
String search(T x)
{
if (root == null) // If the root is null, then tree doesn't exist -> return null
return null;
return root.search(x).toString(); // Else begin a recursive search from the root.
}
void clear()
{
root = null;
size = 0;
}
void traverseTree()
{
ordered = new ArrayList<>(); // Reset the ordered list. traverseTree will be only called in case of
modification
traverse(root); // Initialize traversal from the root.
}