Deep copy of my graph implementation

Hi guys..
I trying to debug my graph implementation, and have come to the conclusion that my copy of my graph isn't done properly .. So how do i do it?

The copy is needed to compute a new state based on the previous state.

When i compare the memory address of an adjacent node in a vertex, with the node itself in the graph, its obvious that they aren't the same, and therefore changing something on a adjacent node, doesn't change anything on the node itself.

I need to implement some form of deep copying, but don't know how as I have nested structs and so on, shallow copying is what i've been doing until now, which clearly failed..

Here is my implementation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
struct vertex
{
   Node *current;
   Node *adjacent;

};

struct node
{
    char town;
    vector<vertex> neighbours;
};


class graph{
public:
    graph();
    graph(const graph &obj);
    int row;
    int col;
    char **map;
    vector<Node> roadmap; //Being the graph
    graph(std::string file);
Last edited on
Topic archived. No new replies allowed.