oop - Inheritance tree: should undirected graph be subclass of directed graph? -


i implementing simple graph library practice. have created base class graph , have derived directedgraph. wondering if should derive undirectedgraph class directedgraph or should derive graph class itself. undirected graph directedgraph in edge u v implies edge v u. please let me know best way implement graph hierarchy.

also , graph class has list of graphvertex. should graphvertex class hold data edges going vertex or should graph class hold data edges.

yeah, ideally should structure inheritance in way make sense in real world application. undirected , directed graphs both graphs, best bet inheriting there.

your graph class include -> (c++)

vector<node*> nodes; 

whereas directed graph hold edges itself.

also, have implemented this, personal , humble suggestion store

dictionary<int, dictionary<int, int>>  

(c++ dictionary unordered_map).

this dictionary list of pairs of nodes pair of node connected weight.

that weighted graph.

hopefully answer, doesn't include code might set on right track.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -