public string FindLongestCommonSubstring(string ending1, string ending2)
{
//find the deepest node that has both ending1 and ending2 in its children
deepestCommonNode = root;
//traverse the nodes to find the deepest common one
Traverse(root);
TreeNode currentNode = deepestCommonNode;
string output = "";
while (currentNode != root)
{
output = currentNode.Value + output;
currentNode = currentNode.parent;
}
return output;
}