954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

how to point to the parent node using a struct

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.

cool_zephyr
Junior Poster in Training
75 posts since Apr 2009
Reputation Points: 8
Solved Threads: 9
 

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

mazzica1
Junior Poster
147 posts since Oct 2011
Reputation Points: 9
Solved Threads: 27
 


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

_parent=(object)parent;
cool_zephyr
Junior Poster in Training
75 posts since Apr 2009
Reputation Points: 8
Solved Threads: 9
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: