Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef GRAFURI_GRAF_H
- #define GRAFURI_GRAF_H
- #define NR_NODURI 5
- struct Graf {
- char V[NR_NODURI];
- int E[NR_NODURI][NR_NODURI];
- };
- void afisareGraf(Graf g);
- int grad(Graf g);
- int numarMuchii(Graf g);
- bool esteOrientat(Graf g);
- bool estePonderat(Graf g);
- void afisareDrumCelMaiScurt(Graf g, int s, int D[]);
- #endif
- #include <iostream>
- #include <list>
- #include <math.h>
- #include <queue>
- #include "Graf.h"
- using namespace std;
- void afisareGraf(Graf g)
- {
- cout << " * ";
- for (int i = 0; i < NR_NODURI; ++i)
- {
- cout << " " << g.V[i] << " ";
- }
- cout << endl;
- for (int i = 0; i < NR_NODURI; ++i)
- {
- cout << " " << g.V[i] << " ";
- for (int j = 0; j < NR_NODURI; ++j)
- {
- cout << " " << g.E[i][j] << " ";
- }
- cout << endl;
- }
- cout << endl;
- }
- int grad(Graf g)
- {
- return NR_NODURI;
- }
- int numarMuchii(Graf g)
- {
- int nrMuchii = 0;
- for (int i = 0; i < NR_NODURI; ++i)
- {
- for (int j = 0; j < NR_NODURI; ++j)
- {
- if (g.E[i][j] != 0)
- {
- ++nrMuchii;
- cout << "(" << g.V[i] << ", " << g.V[j] << "); ";
- }
- }
- }
- cout << endl;
- cout << "Exista " << nrMuchii << " muchii." << endl;
- return nrMuchii;
- }
- bool esteOrientat(Graf g)
- {
- for (int i = 0; i < NR_NODURI; ++i)
- {
- for (int j = 0; j < i; ++j)
- {
- if (g.E[i][j] != g.E[j][i])
- {
- return true;
- }
- }
- }
- return false;
- }
- bool estePonderat(Graf g)
- {
- for (int i = 0; i < NR_NODURI; ++i)
- {
- for (int j = 0; j < NR_NODURI; ++j)
- {
- if (abs(g.E[i][j]) > 1)
- {
- return true;
- }
- }
- }
- return false;
- }
- void afisareDrumCelMaiScurt(Graf g, int s, int D[])
- {
- for (int i = 0; i < NR_NODURI; ++i)
- {
- if (i == s)
- {
- continue;
- }
- cout << "Costul minim de la" << g.V[s] << " la " << g.V[i] << ": " << D[i] << endl;
- }
- }
- #include <iostream>
- #include "Graf.h"
- using namespace std;
- int main() {
- Graf G = {
- { 'A', 'B', 'C', 'D', 'E' },
- {
- { 0 , 3 , 2 , 0 , 0 },
- { 0 , 0 , 4 , 2 , 0 },
- { 0 , 0 , 1 , 2 , 0 },
- { 0 , 1 , 2 , 0 , 1 },
- { 0 , 0 , 1 , 0 , 0 }
- }
- };
- afisareGraf(G);
- cout << "Muchiile sunt=" << endl;
- cout << "Gradul grafului= " << grad(G) << endl;
- numarMuchii(G);
- cout << endl;
- if (esteOrientat(G))
- {
- cout << "Graful este orientat.";
- }
- else
- {
- cout << "Graful nu este orientat.";
- }
- cout << endl;
- if (estePonderat(G))
- {
- cout << "Graful este ponderat.";
- }
- else
- {
- cout << "Graful nu este ponderat.";
- }
- cout << endl << endl;
- cout << endl << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement