Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I know there is not tree structure in .Net Framework, it's interesting, I think the tree is one of most useful data strucutres. Syntax tree, object inheritance tree, and xml tree, even .net use tree that frequently, why don't supply a common tree structure?

I have found a open source solution? Generic Tree <t> in C#[^]

Is there any more?
Posted
Updated 28-Jun-11 22:21pm
v3

There is this one: Generic Tree Container in C# 2.0[^]
And this: A Generic Tree Collection[^]

But if you try googling, you will find loads more: Google[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 29-Jun-11 2:49am    
Good to use the well-developed code (my 5) but...
It's too simple.

Please see my solution.
--SA
I think a tree structure is not available in standard .NET libraries because writing it using available collections suck as generic List would take… minutes, certainly less then an hour.

Hard to believe?

Here is the idea:

C#
using NodeList = System.Collection.Generic.List<TreeNode>

class TreeNodeData {
   //later on you can make it a generic type
}
class TreeNode {
   TreeNodeData TreeNodeData;
   NodeList Children = new NodeList(); //here is where the recursive nature comes up
   //...   
}


Are you getting it?

Add constructor, accessors, operations and you're done!

—SA
 
Share this answer
 
v5
Comments
OriginalGriff 29-Jun-11 3:08am    
An hour? :WTF: That's like, foreveh, man! :laugh:
Sergey Alexandrovich Kryukov 29-Jun-11 3:19am    
Griff,
If you mean you personally do it faster, I will readily agree. I mean an average man. :-)

Thank you.
--SA
OriginalGriff 29-Jun-11 3:21am    
SA, no, sorry - we need a sarcasm icon - I meant that a whole hour is far too much time and effort for most Q&A posters to spend on a project! :laugh:
Sergey Alexandrovich Kryukov 29-Jun-11 3:56am    
Oh yes. You know, somehow I felt the sarcastic tone of your voice through your writing note. I guess you know how. :-)
--SA
Thinking Stone1 29-Jun-11 4:31am    
May be it's not so easy, you need to consider sort, traversing, insertion, retrieveal, also performace, serialization, etc.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900