Skip to content

Instantly share code, notes, and snippets.

@chermehdi
Created September 28, 2016 12:09
Show Gist options
  • Save chermehdi/9d9b009e5b1d3231babf77a849063c51 to your computer and use it in GitHub Desktop.
Save chermehdi/9d9b009e5b1d3231babf77a849063c51 to your computer and use it in GitHub Desktop.
a bfs implementation using cpp
#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