473,397 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Creating a tree with generics

I need to implement a tree structure that can accept various types of
classes or structs. When the tree is created, all of its nodes are
based on a single type and not a mixture of types.

Generics seem to be the solution. However when I look at the
System.Collections.Generic namespace, there isn't anything specific
for building generic trees. There are however classes in this
namespace that I can use to build a tree. My question is, is this the
way I should go about creating the tree? Or do any of the existing
classes in this namespace have built-in tree functionality?

My tree is not for GUI purposes, so I don't want to use the TreeView
class which appears to have limitations that are overcome by Generics.

Thanks

May 9 '07 #1
2 8865
The simplest way would be to use an open source implementation, e.g. http://www.codeproject.com/csharp/treecollection2.asp

By the way, there are several other open source C# collection framewroks,
e.g. C5 (http://www.itu.dk/research/c5/) and PowerCollections (http://www.wintellect.com/PowerCollections.aspx).

These don't have a tree, though.
May 9 '07 #2
Polaris431,

There isn't any data structure out of the box in the framework which
will help you. However, you can use generics yourself to create tree
structure which takes a parameterized type for the value of your nodes.

As Neils said as well, there are third party implementations which might
be suitable for you as well.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Polaris431" <po********@gmail.comwrote in message
news:11**********************@w5g2000hsg.googlegro ups.com...
>I need to implement a tree structure that can accept various types of
classes or structs. When the tree is created, all of its nodes are
based on a single type and not a mixture of types.

Generics seem to be the solution. However when I look at the
System.Collections.Generic namespace, there isn't anything specific
for building generic trees. There are however classes in this
namespace that I can use to build a tree. My question is, is this the
way I should go about creating the tree? Or do any of the existing
classes in this namespace have built-in tree functionality?

My tree is not for GUI purposes, so I don't want to use the TreeView
class which appears to have limitations that are overcome by Generics.

Thanks

May 9 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ralf Höppner | last post by:
Does anyone know, if it is possible to create an explorer-like expandable tree from an XML File ? Maybe using XSLT ? I'd like to use it on an HTML web page. thanks ! Ralf
1
by: Ole Nielsby | last post by:
I'm puzzled at how static fields intersect with generics, as the following snippet illustrates. namespace MonkeyParty { abstract class Fruit { } class Apple : Fruit { } class Pear : Fruit {...
9
by: sloan | last post by:
I'm not the sharpest knife in the drawer, but not a dummy either. I'm looking for a good book which goes over Generics in great detail. and to have as a reference book on my shelf. Personal...
8
by: mark.norgate | last post by:
I've run into a few problems trying to use generics for user controls (classes derived from UserControl). I'm using the Web Application model rather than the Web Site model. The first problem...
4
by: Amit Bhatia | last post by:
User-Agent: OSXnews 2.081 Xref: number1.nntp.dca.giganews.com comp.lang.c++:817424 Hi, I have posted this post also for the thread "vector of lists" but since it is about something else...
1
by: shmodi | last post by:
Hi All, I am new here and want to get some help for speeding up and resolving IE issue while creating tree using ajax. My tree contains radio buttons at each level and I am getting all tree...
0
by: eros | last post by:
I am not sure if it is related to this forum. I already created a tree menu using Javascript. Is there a way not to use javascript? because some of the users and browsers are not allowing...
1
by: Sumz | last post by:
what would the syntax be to create new parent and child nodes to an existing tree view. i just need to create text and not link to any where. these nodes would be created at runtime with a button.
3
by: rymonator | last post by:
Hello, I was wondering how I would convert an existing structure to a tree. What I want is basically a family tree. What I have is the following: array ( array(id => 123, p1 => 567, p2 => 765),...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.