Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <list>
- #include <iterator>
- #include <array>
- #include <limits.h>
- #define V 30
- using namespace std;
- void stvoriGraf(list<int> adj[], int nVertex)
- {
- for (int i = 0; i < nVertex; i++) {
- for (int j = 0; j < nVertex; j++) {
- int create_edge = rand() % 15;
- if (create_edge == 1 && i != j)
- adj[i].push_back(j);
- }
- }
- }
- void DFSUtil(list<int> adj[], int v, bool visited[])
- {
- visited[v] = true;
- cout << v << " ";
- list<int>::iterator i;
- for (i = adj[v].begin(); i != adj[v].end(); ++i)
- if (!visited[*i])
- DFSUtil(adj, *i, visited);
- }
- void spojeni(list<int> adj[], int nVertex)
- {
- bool* visited = new bool[V];
- for (int v = 0; v < V; v++)
- visited[v] = false;
- for (int v = 0; v < V; v++)
- {
- if (visited[v] == false)
- {
- DFSUtil(adj, v, visited);
- cout << "\n";
- }
- }
- delete[] visited;
- }
- int main()
- {
- list<int> adj[V];
- stvoriGraf(adj, V);
- cout << "U zadanom grafu pronadeno je n parova od 3 povezana vrha:"<<endl;
- spojeni(adj, V);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement