Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: .NET Trees
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 in C#[^]
 
Is there any more?
Posted 28-Jun-11 20:47pm
Edited 28-Jun-11 23:21pm
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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[^]
  Permalink  
Comments
SAKryukov at 29-Jun-11 2:49am
   
Good to use the well-developed code (my 5) but...
It's too simple.
 
Please see my solution.
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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:
 
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
  Permalink  
v5
Comments
OriginalGriff at 29-Jun-11 3:08am
   
An hour? :WTF: That's like, foreveh, man! :laugh:
SAKryukov at 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 at 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:
SAKryukov at 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
Ray.L14 at 29-Jun-11 4:31am
   
May be it's not so easy, you need to consider sort, traversing, insertion, retrieveal, also performace, serialization, etc.
SAKryukov at 29-Jun-11 5:05am
   
It ***is*** so easy.
All this is implemented via the available properties of the list. This is exactly as difficult as using them. Who needs serialization? (I mean legacy variant). Use Data Contract -- everything is already done for you.
--SA
Ray.L14 at 30-Jun-11 7:42am
   
Yes, we can use many properties of the list, but I still think it depends on the scenario. Like if you just want to sort children of a specific node, traverse in a specific order, retrieve nodes in specific deep, etc. But I still like you idea. My 5.
SAKryukov at 30-Jun-11 13:42pm
   
Thank you, Ray. I agree with you, but for a difference scenario you can also use a different available container instead of list, such as SortedList, SortedDictionary, etc.
 
So, how about formally accepting this solution (green button)?
Than you.
--SA

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

  Print Answers RSS
0 Mathew Soji 334
1 Maciej Los 295
2 BillWoodruff 290
3 Afzaal Ahmad Zeeshan 257
4 DamithSL 225
0 OriginalGriff 6,369
1 Sergey Alexandrovich Kryukov 5,973
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 4,045


Advertise | Privacy | Mobile
Web03 | 2.8.1411019.1 | Last Updated 29 Jun 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100