Davy J
2008-02-26 12:36:15 UTC
Hi all.
I've got a Binary tree implementation that I need a little help with.
my problem is the recursive lhs.Add(item) and rhs.Add(item) call, is there
any way I could refactor this to remove the stack dependancy?
the application is written in Net.2.0 , so no fancy linq replys please :)
Cheers
Dave.
the psudeo code for the Add function. (written in gmail's c# editor)
public void Add(T item)
{
if (this.item == null)
{
this.item = item;
return;
}
if (item < this.item)
{
if (lhs == null)
{
lhs = new TreeNode<T>();
}
lhs.Add(item);
}
else
{
if (rhs == null)
{
rhs = new TreeNode<T>();
}
rhs.Add(item);
}
}
===================================
This list is hosted by DevelopMentor® http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com
I've got a Binary tree implementation that I need a little help with.
my problem is the recursive lhs.Add(item) and rhs.Add(item) call, is there
any way I could refactor this to remove the stack dependancy?
the application is written in Net.2.0 , so no fancy linq replys please :)
Cheers
Dave.
the psudeo code for the Add function. (written in gmail's c# editor)
public void Add(T item)
{
if (this.item == null)
{
this.item = item;
return;
}
if (item < this.item)
{
if (lhs == null)
{
lhs = new TreeNode<T>();
}
lhs.Add(item);
}
else
{
if (rhs == null)
{
rhs = new TreeNode<T>();
}
rhs.Add(item);
}
}
===================================
This list is hosted by DevelopMentor® http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com