We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,099 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

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.

2
Contributors
2
Replies
13 Hours
Discussion Span
1 Year Ago
Last Updated
3
Views
Question
Answered
cool_zephyr
Junior Poster in Training
87 posts since Apr 2009
Reputation Points: 5
Solved Threads: 10
Skill Endorsements: 0

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

mazzica1
Junior Poster
148 posts since Oct 2011
Reputation Points: 9
Solved Threads: 27
Skill Endorsements: 0

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
87 posts since Apr 2009
Reputation Points: 5
Solved Threads: 10
Skill Endorsements: 0
Question Answered as of 1 Year Ago by mazzica1

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0602 seconds using 2.72MB