How to implement Tree in C#

TheCommunicator
TheCommunicator used Ask the Experts™
on
I am not sure what C library supports and what not. I searched online but did not find anything substantial. Can anybody suggest me a good article or guide me with a small code snipped which can help me implement a tree structure in C#?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
How about something like this?

 public class node
    {
         public node ParentNode;
         public int value;

        public node(int Nodevalue)
        {
            this.value = Nodevalue;
        }

        public node(int Nodevalue, node CurrentParent)
        {
            this.value = Nodevalue;
            this.ParentNode = CurrentParent;
        }

        public node lookupParent(node LookupNode)
        {

            return LookupNode.ParentNode;

        }
    }
]

Open in new window

Author

Commented:
I mean I am just starting out from scratch and I am not sure what  would be the optimum way to store the informaiton. should I also include the children's information?

IF I do then it would becode redundant  information and there would be a lot of scope for conflict.
On the other hand if I do not include the children's information then I do not see a good way to traverse the whole tryy given the root node.

Please advise?
Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Commented:
Depends on what you saving...

If you want to represent groups and users - the users would be children and groups would be their nodes...

I'm not sure I fully understood your question though...
Top Expert 2009
Commented:
Yes, you must add field(s) for child nodes, usually for a binary tree, you'd have left child and right child. Otherwise, you cannot traverse the tree. ParentNode pointer is optional, but good to have, but references for child node is not optional or you cant build the tree.

Author

Commented:
Ok Yes, you are right. Thanks.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial