Category : adjacency-matrix

I am getting runtime error while running the following code on leetcode 48; class Solution { public: void rotate(vector<vector<int>>& matrix) {vector<vector<int>>copy; for(int i=0;i<matrix.size();i++) { for(int j=0;j<matrix.size();j++) { copy[j][matrix.size()-i-1]=matrix[i][j]; } } for(int i=0;i<matrix.size();i++) { for(int j=0;j<matrix.size();j++) { matrix[i][j]=copy[i][j]; }} }}; as Line 1034: Char 9: runtime error: reference binding to null pointer of type ‘std::vector<int, std::allocator>’ ..

Read more

I have an adjacency matrix for a graph. And I need to output all the cycles in this graph. How can I do this using dfs? void al_dfs(int tmp_vertex,int** Graph,vector<int>& color,int number,vector<int>& result){ color[tmp_vertex] = 1; for(int i = 0;i<number;i++){ if((color[i] == 0)){ al_dfs(i,Graph,color,number,result); result.push_back(i); }; if((color[i] == 1)){ for(int i = 0;i< result.size();i++) cout ..

Read more

In the boost graph library, there are two popular functions to read in graphs from a file: boost::read_graphviz(), and boost::read_graphml(), for the GraphViz and the GraphML format, respectively. Now both read generically to any type of boost::adjacency_list<…>, as they are derived from the Mutable Graph concept: #include <string> #include <fstream> #include <boost/graph/adjacency_list.hpp> #include <boost/graph/adjacency_matrix.hpp> #include ..

Read more

Here is my Graph class which contains adjacency list: typedef std::vector<std::list<unsigned int>> AdjacencyList; class Graph { public: Graph(size_t vertices); // to test // Constructs a ‘Graph’ object, // expecting a pointer to the ‘AdjacencyList’ // and the number of vertices Graph(std::shared_ptr<AdjacencyList> adjListPtr, int vertices); // to test // Constructs a ‘Graph’ object from ‘AdjacencyMatrix’ object ..

Read more