-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBFSPseudoCode.cpp
More file actions
33 lines (30 loc) · 969 Bytes
/
BFSPseudoCode.cpp
File metadata and controls
33 lines (30 loc) · 969 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
Psuedo Code
Put the start vertex on the stack/in the queue
while the stack or queue is not empty, do
take a vertex X from the stack or queue;
if(X has not been visited)
mark X visited;
generate all neighbors of X;
for each neighbor Y {
if (Y is not visited)
put Y on stack/in queue;
Put the start vertex on the stack/in the queue
while the stack or queue is not empty, do
take a vertex X from the stack or queue;
if(X has not been visited)
mark X visited;
generate all neighbors of X;
for each neighbor Y {
if (Y is not in_stack_or_queue)
mark Y as in_stack_or_queue;
put Y on stack/in queue;
Put the start vertex on the stack/in the queue
while the stack or queue is not empty, do
take a vertex X from the stack or queue;
if(X has not been visited)
mark X visited;
generate all neighbors of X;
for each neighbor Y
if (Y reached_from is undefined)
mark Y reached_from X;
put Y on stack/in queue;