Advertisement
k0mZ

Untitled

May 9th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. bool GList::isStronglyConnected()
  2. {
  3. //obidje za svaki cvor DFS
  4. //ako ne obidje sve nije
  5. //Strongly Connected.
  6.  
  7. LNode* t = this->start;
  8. int r;
  9.  
  10. while (t != nullptr)
  11. {
  12. cout << "\n";
  13. r = this->depthFirstSearch();
  14.  
  15. cout << "\n";
  16.  
  17. if (r != this->countNodes)
  18. {
  19. return false;
  20. }
  21.  
  22. this->setUnvisited();
  23.  
  24. t = t->next;
  25. }
  26.  
  27. return true;
  28.  
  29. }
  30.  
  31. void GList::setUnvisited()
  32. {
  33. LNode* t = this->start;
  34. while (t != nullptr)
  35. {
  36. t->visited = false;
  37. t = t->next;
  38. }
  39. return;
  40.  
  41. }
  42.  
  43.  
  44. int GList::depthFirstSearch()
  45. {
  46. int r = 0;
  47.  
  48. Stek* a = new Stek(this->countNodes);
  49. LNode* ptr = this->start;
  50. string b;
  51.  
  52. a->push(ptr);
  53.  
  54. while (!a->isEmpty())
  55. {
  56. ptr = a->pop();
  57.  
  58.  
  59. if (!ptr->visited)
  60. {
  61. ptr->visited = true;
  62.  
  63. b += ptr->symbol;
  64. b += " ";
  65. r++;
  66.  
  67.  
  68. Edge* ptrNext = ptr->izlGrana;
  69.  
  70. //nabacamo susede
  71.  
  72. while (ptrNext != nullptr)
  73. {
  74. a->push(ptrNext->dstNode);
  75.  
  76. ptrNext = ptrNext->nextBranch;
  77. }
  78.  
  79. }
  80. }
  81.  
  82.  
  83. cout << b;
  84. return r;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement