O‘ZBEKISTON RESPUBLIKASI AXBOROT TEXNOLOGIYALARI VA
KOMMUNIKATSIYALARINI RIVOJLANTIRISH VAZIRLIGI
MUHAMMAD AL-XORAZMIY NOMIDAGI
TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI
ma’lumotlar tuzilmasi va algoritmlar fanidan
5-AMALIY ISH
Guruh: SWD015
Bajardi:Baxtiyorov Abdullo
Tekshirdi: Ganixodjayeva Dilfuza
4-variant.
Misol: Insident matritsasidan qo'shni matritsani hosil qiladigan funktsiyani tavsiflang.
#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;
}
Dostları ilə paylaş: |