joby

joby

  • NA
  • 6
  • 0

please help me with this code,explanations required

Sep 30 2009 1:06 PM

public
SortTreeNode Add(ref string str)
{
SortTreeNode node;
if(Root == null)
{
Root =
new SortTreeNode();
node = Root;
}
else
{
node = Root;
while(true)
{
if(node.Text == str)
{
node.Count++;
return node;
}
if(node.Text.CompareTo(str) > 0)
{
// add the node at the small branch
if(node.Small == null)
{
node.Small =
new SortTreeNode();
node.Small.Parent = node;
node = node.Small;
break;
}
node = node.Small;
}
else
{
// add the node at the great branch
if(node.Great == null)
{
node.Great =
new SortTreeNode();
node.Great.Parent = node;
node = node.Great;
break;
}
node = node.Great;
}
}
}
node.Text = str;
node.ID =
this.Count++;
node.Count++;
Modified =
true;

return node;
}

public void Save(string fileName, System.Text.Encoding code)
{
FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None);
StreamWriter writer = new StreamWriter(stream, code);

BitArray bitArray = new BitArray(this.Count, false);
SortTreeNode node = this.Root;
int nCount = this.Count;
while(nCount > 0)
{
if(node.Small != null && bitArray.Get(node.Small.ID) == false)
node = node.Small;
else if(bitArray.Get(node.ID) == false)
OutNode(node, writer, bitArray,
ref nCount);
else if(node.Great != null && bitArray.Get(node.Great.ID) == false)
node = node.Great;
else
{
if(bitArray.Get(node.ID) == false)
OutNode(node, writer, bitArray,
ref nCount);
node = node.Parent;
}
}
writer.Close();
stream.Close();

Modified =
false;
}

Answers (1)