Hello there..i'm trying to implement a tree in C#..the basic node structure is give below

struct node
        public int _x;
        public int _y;
        public int _cost;
        public node _parent;

        public pos(int i, int j,int cost,pos parent)
            _x = i;
            _y = j;
            _cost = cst;
            _parent = parent;

I get the following error when i try to compile : 'node' causes a cycle in the struct layout
This was the way we used to make a tree in C++..but it's confusing in C#..could anyone please enlighten me?? Any help would be appreciated.

if struct/class doesnot mater you use class and it will solve the problem

hey thanks for the tip..it works but i found a way around..i need to use boxing to store the _parent node in a object variable type

public object _parent;

now in the constructor

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.