FW-4.2- decide whether the two nodes have circle - JAVA VERSION - 2013年12月20日20:22:25
来源:互联网 发布:淘宝上卖的jbl音响 编辑:程序博客网 时间:2024/04/28 18:04
Given a directed graph, design an algorithm to find out whether there is a route between two nodes.
// bfs seems easy so ; we will use dfs;public boolean isconnected(EdgeNode e1,int dstNum)// the first node connected to the node 1 and node 2;{Stack<EdgeNode> isc_stack = new Stack<EdgeNode>();isc_stack.push(e1);while(!isc_stack.isEmpty()){EdgeNode head = isc_stack.pop();if(head.isVisted == false){head.print();if(head.inNode == dstNum){return true;}head.isVisted =true;}Iterator<EdgeNode> it_from = G.get(head.fromNode).iterator();while(it_from.hasNext()){EdgeNode x = it_from.next();if(x.isVisted == false)isc_stack.push(x);}Iterator<EdgeNode> it_in = G.get(head.inNode).iterator();while(it_in.hasNext()){EdgeNode x = it_in.next();if(x.isVisted == false)isc_stack.push(x);}}return false;}// test whether from the s->e->s;public boolean iscyccnct(int startNd,int endNd){if(G.get(startNd).size() == 0 || G.get(endNd).size() ==0){System.out.println("there is no line in one of the node");return false;}else{ /*System.out.print(startNd + " ~->>~ "+ endNd);System.out.println(isconnected(G.get(startNd).get(0), G.get(endNd).get(0)));System.out.print(endNd + " ~->>~ "+ startNd);System.out.println(isconnected(G.get(endNd).get(0), G.get(startNd).get(0)));*/boolean result = this.isconnected(G.get(startNd).get(0),endNd) && this.isconnected(G.get(endNd).get(0),startNd) ;this.clear();return result ;}}
0 0
- FW-4.2- decide whether the two nodes have circle - JAVA VERSION - 2013年12月20日20:22:25
- fw 3.5 -2013年12月16日21:02:12 - two stacks make a queue- java version -
- fw - dfs: stack/recursive ; bfs : stack/recursive- java version - 2013年12月20日18:37:18
- FW - check whether tree is balanced or not - find the max and min of one tree- 2013年12月18日13:12:04
- fw 3.6 - stack sort- java version - 2013年12月16日23:23:32
- fw - pre_order_traverse - 2013年12月17日13:36:58 - java version
- fw-3.5 - queue by 2 stacks - C++ version - 2013年12月16日21:20:06
- FW-binary - tree - with id and sibling connected - java version 2013年12月18日1:21
- fw-2013年12月16日19:48:30 - haino tower - C++ version
- fw-2013年12月16日16:54:13 - haino tower via stack -java
- FW - java - Adjacency list- 2013年12月19日15:42:04- BFS - edge Node
- fw 2013年12月14日12:51:42 selection_sort
- fw ->>>>>>> 2013年12月13日23:16:30 ->> quick_sort
- 2015年7月11日-FW
- fw -BFS & DFS tree-2-013年12月17日17:56:33
- Given a number m, how to decide whether this m is in the matrix
- Detect whether two rectangles have common area or not -- Amazon
- 12月20日
- stdafx.h到底有什么用?
- 13岁少女生3胞胎 孩他爹是61岁老汉
- OPENTLD学习总结
- leaflet.js开源地图
- 2013.12.21
- FW-4.2- decide whether the two nodes have circle - JAVA VERSION - 2013年12月20日20:22:25
- jquery遍历json键值对
- 解决Smarty中truncate截取中文字符乱码问题
- 位运算
- window.opener
- C#面试题
- 短网址 dwz.cn
- 高性能、高流量Java Web
- Eclipse中设置背景颜色与字体大小和xml文件中字体大小调整