BFS (Bridth First Search) can be implemented by a queue.
Procedure is like this: (Q is Queue)
1, Put 1 in Q : ->1 (front)
2, Read the front of Q (which is 1) and put its children in Q: ->4->3->2
3, Repeat 2
....
Also, DFS (Depth First Search) can be implemented by a stack.
Procedure is like this: (S is Stack)
1, Put 1 in S: 1<- (bottom)
2, Read the top of S which is 1 and put its children into S: 2<-7<-8
3, Repeat 2
....
Think about it!
原文地址:http://www.cnblogs.com/miaoz/p/3982808.html