Last active
March 17, 2017 06:50
-
-
Save linnet8989/4f989b40c72c077b86440417fc001562 to your computer and use it in GitHub Desktop.
广度优先搜索 代码编写指引
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
函数(参数:节点) | |
{ | |
定义:一个队列 | |
初始化:节点入队 | |
搜索过程: | |
循环(当队列为不为空时继续) | |
{ | |
1. 队首出队 | |
2. 此处插入验证(可在此处退出)条件 | |
3. 将出队节点的子节点加入队列 | |
} | |
} | |
低配版(只有C的数组和结构体可用): | |
函数(参数:节点) | |
{ | |
定义:一个足够长的数组,索引i、j | |
初始化:i置0,j置1,[0]赋值为节点值 | |
搜索过程: | |
循环(当i小于j时继续) | |
{ | |
1. 取出[i]中的节点 | |
2. 此处插入验证(可在此处退出)条件 | |
3. 循环将节点(或[i])的子节点赋值给[j],每加入一个,令j加一 | |
4. i加一 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment