I'd do something like this:
class Entity;
class Relationship // usually called Edge
{
Entity *from;
Entity *to;
// other data
};
class Entity // usually called Node
{
list<Relationship*> incoming;
list<Relationship*> outgoing;
};
vector<Entity*> roster;
You might want to wrap roster
in some sort of EntityHandler
class, to manage all of those pointers.
For #1, look up an Entity in the roster by its number (e.g. roster[5]
), and that Entity's outgoing
is what you want -- you can do a shallow copy (of the pointers), or a deep copy (of the Relationships).
For #2, look up the Entity and iterate over both of its Relationship lists; for each Relationship, remove the corresponding pointer from the list in the Entity at the other end, then delete the Relationship. Then delete the Entity. And don't forget to set the pointer in the roster to NULL.