private string FindSuccessorRec(string wordPart, Node curNode,string carry)
{
var matches = MatchingConsecutiveCharacters(wordPart, curNode);
if ((matches == 0) || (curNode == _root) ||
((matches > 0) && (matches < wordPart.Length) ))
{
var newLabel = wordPart.Substring(matches, wordPart.Length - matches);
foreach (var child in curNode.SubNodes)
if (child.Label.StartsWith(newLabel[0].ToString()))
return FindSuccessorRec(newLabel, child, carry + curNode.Label);
return curNode.Label;
}
else if (matches < curNode.Label.Length)
{
return carry + curNode.Label;
}
else if (matches == curNode.Label.Length)
{
carry = carry + curNode.Label;
int min = int.MaxValue;
int index = -1;
for (int i = 0; i < curNode.SubNodes.Count;i++ )
if (curNode.SubNodes[i].Label.Length < min)
{
min = curNode.SubNodes[i].Label.Length;
index = i;
}
if (index > -1)
return carry + curNode.SubNodes[index].Label;
else
return carry;
}
else return string.Empty;
}