Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // graph
- void BFS(int a, vector<int>& vec)
- {
- queue<int> q; q.push(a);
- vec.push_back(a);
- while(!q.empty())
- {
- int x = q.front();
- q.pop();
- cout << x << " ";
- vector<int> helper;
- for(int i = 0; i < numOfVertices; i++)
- {
- if(graph[i].front() == x)
- {
- helper = graph[i];
- break;
- }
- }
- int size = helper.size();
- for(int i = 0; i < size; i++)
- {
- if(!isMember(helper[i],vec))
- {
- q.push(helper[i]);
- vec.push_back(helper[i]);
- }
- }
- }
- }
- void DFS(int a, vector<int>& vec)
- {
- vec.push_back(a);
- cout << a << " ";
- vector<int> helper;
- for(int i = 0; i < numOfVertices; i++)
- {
- if(graph[i].front() == a)
- {
- helper = graph[i];
- break;
- }
- }
- int size = helper.size();
- for(int i = 0; i < size; i++)
- {
- if(!isMember(helper[i],vec))
- {
- DFS(helper[i],vec);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement