Grundsätzlich habe ich eine Adj_Matrix erzeugt und ich möchte eine Adj_Liste von der Adj_Matrix machen ... Allerdings bekomme ich immer einen Fehler, der sagt "Keine Übereinstimmung für Anruf ..." Ich versuchte es ohne aPair ich noch bekomme den gleichen Fehler Ich kann nicht herausfinden, was mein Problem ist. Kann mir jemand sagen, warum die Liste nicht funktioniert? die Liste ist ganz am Ende des CodesAdjazenzliste Fehler mit Liste
int **gen_random_graph(int n)
{
srand(time(0));
int **adj_matrix = new int*[n];
for(int i = 0; i < n; i++)
{
for (int j = i; j < n; j++) //generating a N x N matrix based on the # of vertex input
{
adj_matrix[i] = new int[n];
}
}
for(int u = 0; u < n; u++)
{
for (int v = u; v < n; v++)
{
bool edgeOrNot = rand() % 2; //decide whether it has an edge or not
adj_matrix[u][v] = adj_matrix[v][u] = edgeOrNot;
if(adj_matrix[u][v] == true)
{
adj_matrix[v][u] = true;
if(u == v) //We can't have i = j in an undirected graph so we set it to false
{
adj_matrix[u][v] = -1;
}
}
else //if adj_matrix[u][v] is false set the symmetry to be false
{
adj_matrix[v][u] = adj_matrix[u][v] = -1;
}
}
}
for(int i = 0; i < n; i++)
{
for(int j = i; j < n; j++) //create the N x N with edges and sets the weight between the edge randomly
{
if(adj_matrix[i][j] == true)
{
int weight = rand() % 10 + 1;
adj_matrix[i][j] = adj_matrix[j][i] = weight;
cout << " (" << i << "," << j << ") " << "weight: " << adj_matrix[i][j] << endl;
}
}
}
for(int i = 0; i < n; i++)
{
vector<int> adj_list;
for(int j = i; j < n; j++)
{
if(adj_matrix[i][j] > 0)
{
int weight = adj_matrix[i][j];
adj_list.push_back(j);
cout << adj_list[i] << " " << endl;
}
}
}
print(n,adj_matrix);
return (adj_matrix);
}
Kann adj_list aufgerufen werden? –
umm Ich habe keine Funktion für adj_list gemacht, also nein, ich denke nicht, dass es aufgerufen werden kann. Im Grunde habe ich eine Adj_Matrix erzeugt und nun muss ich aus der AdjMatrix Adj_List erstellen – Darkflame
hmmmm aber ich brauche nur das Gewicht von adj_matrix [i] [j] gibt es eine Möglichkeit, das zu beheben? – Darkflame