rendered paste bodyvoid Insert(TreeNode<string>* root, string insertString)
{
TreeNode<string>* walk;
walk = root;
if (insertString <= walk->Value)
{
walk->AVL--;
if (!walk->Left)//base case
{
TreeNode<string>* newLeaf = new TreeNode<string>(insertString);
walk->Left = newLeaf;
}
else
{
Insert(walk->Left, insertString);
}
}
else
{
walk->AVL++;
if (!walk->Right)//base case
{
TreeNode<string>* newLeaf = new TreeNode<string>(insertString);
walk->Right = newLeaf;
}
else
{
Insert(walk->Right, insertString);
}
}
if (root->AVL == -2 && root->Left && root->Left->AVL == -1)//left-left
{
//rotate right around parent
TreeNode<string>* temp;
temp = root;
root = root->Left;
root->Right = temp;
temp->Left = NULL;
}
else if (walk->AVL == -2 && walk->Left && walk->Left->AVL == 1)//left-right
{
//rotate left around child then rotate right around parent
}
else if (walk->AVL == 2 && walk->Right && walk->Right->AVL == 1)//right-right
{
//rotate left around parent
}
else if (walk->AVL == 2 && walk->Right && walk->Right->AVL == -1)//right-left
{
//rotate right around child, then left around parent
}
}