Advertisement
piotrjanuszek

Untitled

Feb 3rd, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. void BFS(City* start, City** Cities)
  2. {
  3.     int visited[21] = { 0 };
  4.     QHead* QueueHead = (QHead*)calloc(1, sizeof(QHead));
  5.     QPush(start, QueueHead);
  6.     visited[start->citynum] = 1;
  7.     while (!QIsEmpty(QueueHead))
  8.     {
  9.         City* v = QTop(QueueHead);
  10.     //  cout << v->citynum<<"  ";
  11.         Con* p = Cities[v->citynum-1]->Head->pHead;
  12.         while (p)
  13.         {
  14.             int b = p->cityB;
  15.             if (!visited[b])
  16.             {
  17.                 QPush(Cities[b - 1], QueueHead);
  18.                 cout << Time(p)<<endl;
  19.                 p->time = Time(p);
  20.                 visited[b] = 1;
  21.             }
  22.             p = p->next;
  23.         }
  24.     }
  25.     FreeQ(QueueHead);
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement