Mustaqil ishi-4




Download 61,74 Kb.
bet12/12
Sana13.05.2024
Hajmi61,74 Kb.
#229485
1   ...   4   5   6   7   8   9   10   11   12
Bog'liq
Mustaqil ishi-4-kompy.info

Qo'shnilik matritsasi:
qo'shnilik matritsasi - bu V x V o'lchamdagi 2D massiv, bu erda V - grafikdagi uchlari soni. 2D massiv adj[][] bo‘lsin, slot adj[i][j] = 1 i cho‘qqidan j


#include
using namespace std;
void addEdge(vector adj[], int u, int v)
{
adj[u].push_back(v);
adj[v].push_back(u);
}
void printGraph(vector adj[], int V)
{ for (int v = 0; v < V; ++v) {
cout << "\n Adjacency list of vertex " << v<< "\n head ";
for (auto x : adj[v]) cout << "-> " << x; printf("\n");
}
}
int main()
{ int V = 5;
vector adj[V]; addEdge(adj, 0, 1);
addEdge(adj, 0, 4);
addEdge(adj, 1, 2);
addEdge(adj, 1, 3);
addEdge(adj, 1, 4);
addEdge(adj, 2, 3);
addEdge(adj, 3, 4);
printGraph(adj, V);
return 0;
}
http://kompy.info

Download 61,74 Kb.
1   ...   4   5   6   7   8   9   10   11   12




Download 61,74 Kb.