4.1 Route Between Nodes
2015-10-27 14:21
423 查看
For all directed graph problem, I use struct DirectedGraphNode:
Simply BFS traverse Graph:
Note: BFS always first think about queue!
struct DirectedGraphNode { int label; vector<DirectedGraphNode *> neighbors; DirectedGraphNode(int x) : label(x) {}; };
Simply BFS traverse Graph:
bool hasRoute(vector<DirectedGraphNode*> graph, DirectedGraphNode* s, DirectedGraphNode* t) { // write your code here queue<DirectedGraphNode*> q; q.push(s); while(!q.empty()){ DirectedGraphNode* cur = q.front(); q.pop(); for(auto node : cur->neighbors) q.push(node); if(cur == t) return true; } return false; }
Note: BFS always first think about queue!
相关文章推荐
- Purpose of the MacroMobile Project 1029 ------- No deletion of any Doc for the project
- String.Empty,NULL和""的区别
- C++算法--图算法读书笔记1
- FusionCharts中文乱码问题
- [convex hall] ZOJ 1518 This Sentence is False
- GraphData之 Bridge 计算
- 搜索专题
- poj 1062 昂贵的聘礼
- poj 1094 Sorting It All Out
- Icarnegie SSD4 Exercise1 Answer
- (转载)机器学习方法的PPT
- chapter 22 Elementary Graph Algorithms
- Reading a paper of Texture'05 submission #050 "Hole Filling Throng Photomontage"
- 学习VC++深入浅出——绘图操作
- 深度优先、广度优先java实现
- 推荐18个基于 HTML5 Canvas 开发的图表库
- The 7th Zhejiang Provincial Collegiate Programming Contest - G(Wu Xing)
- webfocus图表
- webfocus精细图表
- 建立简单图片过程