码迷,mamicode.com
首页 > 其他好文 > 详细

BFS and Queue

时间:2014-09-20 04:36:36      阅读:237      评论:0      收藏:0      [点我收藏+]

标签:http   ar   sp   on   c   ad   r   bs   tt   

BFS (Bridth First Search) can be implemented by a queue.

bubuko.com,布布扣

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.

bubuko.com,布布扣

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!

BFS and Queue

标签:http   ar   sp   on   c   ad   r   bs   tt   

原文地址:http://www.cnblogs.com/miaoz/p/3982808.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!