seraching a Btree (.net Generics), how?

J

Jeff

hi

..net 2.0

I have a custom class:

public class Comment
{
private Guid _id;
private Guid _userid;
private Guid _article;
private Guid _parent;
private List<Comment> _replies;

public comment() {}
}

okay, my DAL return a list of all comments associated with an article. Some
of those comments might be replies to other comments etc. Now in my BLL (the
class above is within BLL) I want to fix this so that replies to another
comment is not added to the root list but to the comment they are replies
too....

My problem is how do I search my btree to locate where to put the comment,
maybe .NET Generics have some built in feature for this?

I started with this code:
Comment comment = GetCommentFromCommentDetails(record); //Get comment from
DAL
if (comment._parent == Guid.Empty) //if no parent, then add to root list
comments.Add(comment);
else
{
//Here I have to search the btree, not sure how?
}


any suggestions? any tips about how to display these comments in a data
presentation control is welcome too.
 
B

bruce barker

pretty standard recursive search. add this method to the class:


public Comment FindCommentByID(Guid id)
{
if (this._id == id)
return this;
foreach (var comment in _replies)
{
var childComment = comment.FindCommentByID(id);
if (childComment != null)
return childComment;
}
return null;
}

-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top