Created
December 13, 2016 00:04
-
-
Save ahmadyan/bd14a9015dc5fed450f8bafdf40ff99f to your computer and use it in GitHub Desktop.
BFS Implementation with std::dequeu
This file contains 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
int bfs_deque(Graph* g){ | |
int sig=0; | |
vector<bool> visited(g->getSize(), false); | |
deque<int> q; | |
auto init = rand()%g->getSize(); | |
q.push_back(init); | |
visited[init]=true; | |
while(!q.empty()){ | |
auto u = q.front(); | |
sig += u; | |
q.pop_front(); | |
for(auto v: g->adj_list[u]){ | |
if(!visited[v]){ | |
visited[v]=true; | |
q.push_back(v); | |
} | |
} | |
} | |
return sig; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment