Created
September 28, 2016 12:09
-
-
Save chermehdi/9d9b009e5b1d3231babf77a849063c51 to your computer and use it in GitHub Desktop.
a bfs implementation using cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <queue> | |
#include <vector> | |
#include <string.h> | |
vector<vector<int> > graph; | |
void bfs(int src){ | |
bool visited[1000]; | |
memset(visited, false, sizeof(visited)); | |
queue<int> q; | |
q.push(src); | |
visited[src] = true; | |
while(!q.empty()){ | |
int n = q.front(); q.pop(); | |
for(auto it: graph[n]){ | |
if(visited[it]) continue; | |
visited[it] = true; | |
q.push(it); | |
} | |
} | |
} | |
int main(){ | |
//1-fill vector graph | |
//2- call bfs (src node) | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment