SHARE
TWEET

d

BowserFlash13 May 29th, 2020 631 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3. #include <list>
  4. #include <iterator>
  5. #include <array>
  6. #include <limits.h>
  7.  
  8. #define V 30
  9.  
  10. using namespace std;
  11.  
  12. void stvoriGraf(list<int> adj[], int nVertex)
  13. {
  14.     for (int i = 0; i < nVertex; i++) {
  15.         for (int j = 0; j < nVertex; j++) {
  16.             int create_edge = rand() % 15;
  17.             if (create_edge == 1 && i != j)
  18.                 adj[i].push_back(j);
  19.         }
  20.     }
  21. }
  22.  
  23. void DFSUtil(list<int> adj[], int v, bool visited[])
  24. {
  25.     visited[v] = true;
  26.     cout << v << " ";
  27.     list<int>::iterator i;
  28.     for (i = adj[v].begin(); i != adj[v].end(); ++i)
  29.         if (!visited[*i])
  30.             DFSUtil(adj, *i, visited);
  31. }
  32.  
  33. void spojeni(list<int> adj[], int nVertex)
  34. {
  35.     bool* visited = new bool[V];
  36.     for (int v = 0; v < V; v++)
  37.         visited[v] = false;
  38.  
  39.     for (int v = 0; v < V; v++)
  40.     {
  41.         if (visited[v] == false)
  42.         {
  43.             DFSUtil(adj, v, visited);
  44.  
  45.             cout << "\n";
  46.         }
  47.     }
  48.     delete[] visited;
  49. }
  50.  
  51.  
  52.  
  53. int main()
  54. {
  55.     list<int> adj[V];
  56.  
  57.     stvoriGraf(adj, V);
  58.     cout << "U zadanom grafu pronadeno je n parova od 3 povezana vrha:"<<endl;
  59.     spojeni(adj, V);
  60.  
  61.  
  62.     return 0;
  63. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top