Link to home
Start Free TrialLog in
Avatar of TheCommunicator
TheCommunicatorFlag for United States of America

asked on

How to implement Tree in C#

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#?
Avatar of oferam
oferam
Flag of United States of America image

Avatar of TheCommunicator

ASKER

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

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?
ASKER CERTIFIED SOLUTION
Avatar of oferam
oferam
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ok Yes, you are right. Thanks.