Hello all :) Today I am refining my skills on graph theory and data structures. I decided to do a small project in C++ because it\'s been a while since I\'ve worked in C++
This may not be very general approach but thats how I handle adjacency list in most of the cases. C++ has STL library which supports a data structure for linked list named as list
.
Say you have N
nodes in the graph, create a linked list for every node.
list graph[N];
Now graph[i]
represent the neighbours of node i. For every edge i to j, do
graph[i].push_back(j);
The best comfort is no handling of pointers so as segmentation fault errors.
For more reference http://www.cplusplus.com/reference/list/list/