Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void BFS(int x, int graphSize)
- {
- //int graph[5][5] = { { 0, 0, 0, 1, 0 }, { 1, 0, 0, 0, 0 }, { 1, 1, 0, 0, 1 }, { 0, 1, 1, 0, 1 }, { 0, 1, 0, 0, 0 } };
- //int graph[6][6] = { { 0, 0, 0, 1, 0 }, { 1, 0, 0, 0, 0 }, { 1, 1, 0, 0, 1 }, { 0, 1, 1, 0, 1 }, { 0, 1, 0, 0, 0 } };
- queue<int> kolejka;
- bool* V;
- V = new bool[graphSize];
- for (int j = 0; j < graphSize; ++j)
- V[j] = false;
- kolejka.push(x);
- while (!kolejka.empty())
- {
- x = kolejka.front();
- kolejka.pop();
- V[x] = true;
- cout << x << " ";
- for (int j = 0; j < graphSize; ++j)
- {
- if (graph[x][j] != 0 && V[j] == false)
- {
- kolejka.push(j);
- V[j] = true;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement