Initialization & Functions example - achiyazigi/directional-weighted-graph-DS GitHub Wiki

a simple graph initialization:

directed_weighted_graph_DS g = new DWGraph_DS();

adding a node to the graph:

g.addNode(new NodeData(0));

if the key is already exists no action will be executed.

connecting two nodes in the graph:

g.connect(0, 1, 2.4);

in case of non existed keys in the graph (1 or 2) no error will be prompted.

in case of same edge value no action will be executed.

in case of new edge value, an update will be performed.

getting edge:

edge_data val = g.getEdge(0, 1);

in case of non existed edge in the graph, null will be returned.

to retrieve number of edges:

int e = g.edgeSize();

get node by key:

node_info n = g.getNode(0);

in case of non existed key in the graph, n <-null.

get a collection of all the nodes included in g:

Collection<node_info> col = g.getV();

in case of empty graph, col will be empty (not null!!).

get a collection of all the edge_data going out from <some_key>:

Collection<node_info> col = g.getE(<some_key>);

in case of non existed key in the graph, col will be null.

in case of not existed neighbors, col will be empty.

the modifications on the graph is also stored and can be accessed by:

int mods = g.getMC();

⚠️ **GitHub.com Fallback** ⚠️