开发者

What is the best way to store node(i).x and node(i).y array values in c++?

I have to process spatial data which are nodes in a graph.What 开发者_开发技巧data type /variable type /data structure allows me to access the values of i-th node's x value and i-th node's y value.


std::vector would do it.

ie

class Node
{
    std::vector< NODE > mNodes;
public:
    int x, y;
    Node& operator( int i )
    {
        return mNodes[i];
    }
}

Now if you have a Node defined as n you can access the ith node stored in that Node as follows:

Node n;
// Populate Node
int x = n( 12 ).x;
int y = n( 14 ).y;


struct Node{
    float x;
    float y;
}
std::vector<Node> nodes;
std::cout<<nodes.at(i).x;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜