How can I combine these two functions to create a program that will allow a user to enter the count of vertices and then enter the graph edges?
#include <iostream>
using namespace std;
int **malloc2d(int r, int c)
{
int **t = new int*[r];
for(int i = 0; i < r; i++)
t[i] = new int[c];
return t;
}
int main()
{
int i;
int j;
int adj[V][V];
for(i = 0; i < V; i++)
for(j = 0 ; j < V; j++)
adj[i][j] = 0;
for(i = 0; i < V; i++)
adj[i][i]= 1;
while (cin>> i >> j)
{
adj[i][j] = 1;
adj[j][i] = 1;
}
system("pause");
return 0;
}
You could use
std::vector<std::vector<bool>>
orboost::adjacency_matrix
, it's simpler.