Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.06 KB | None | 0 0
  1. void Dijkstra::glupia(int start, int end) {
  2.     reset();
  3.  
  4.     set<int> stos;
  5.     stos.insert(start);
  6.    
  7.     bool visited[255];
  8.     for (int i = 0; i < 255; i++) {
  9.         visited[i] = false;
  10.     }
  11.  
  12.     char litery[] = { 'a', 'b', 'c', 'd', 'e' };
  13.  
  14.     bool stop = false;
  15.     while(!stos.empty() && !stop) {
  16.         cout << "---------------------" << endl;
  17.         int u = *(stos.begin());
  18.         stos.erase(stos.begin());
  19.  
  20.         cout << "u=" << litery[u] << endl;
  21.  
  22.         for (int j = 0; j < nodes[u].size(); j++) {
  23.             if (visited[nodes[u][j].index] && visited[nodes[u][j].index * 2]) continue;
  24.  
  25.             cout << "nodes[u][j].index=" << litery[nodes[u][j].index];
  26.                        
  27.             if (nodes[u][j].index == end) {
  28.                 cout << "   znaleziono!" << endl;
  29.                 continue;
  30.             }
  31.             else {
  32.                 stos.insert(nodes[u][j].index);
  33.             }
  34.             cout << endl;
  35.         }
  36.         if (!stos.empty()) {
  37.             set<int> temp = stos;
  38.  
  39.             int p = *(temp.begin());
  40.             temp.erase(temp.begin());
  41.            
  42.             bool child = false;
  43.             cout << "p=" << litery[p] << endl;
  44.             bool stop = false;
  45.  
  46.             while(!temp.empty()) {
  47.                 int d = *(temp.begin());
  48.                 temp.erase(temp.begin());
  49.                
  50.                 cout << "Szukam " << litery[p] << " wsrod dzieci " << litery[d];
  51.                 for (int j = 0; j < nodes[d].size(); j++) {
  52.                     if (p == nodes[d][j].index) {
  53.                         cout << " : TAK" << endl;
  54.                         child = true;
  55.                         stop = true;
  56.                         break;
  57.                     }
  58.                 }
  59.                 if (!child)
  60.                     cout << " : NIE" << endl;
  61.  
  62.                 if (stop) break;
  63.             }
  64.            
  65.             visited[u] = !child;
  66.             if (visited[u]) {
  67.                 cout << "visited[" << litery[u] << "]=true" << endl;
  68.             }
  69.         }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement