FWNX-creates a linked list of all the nodes at each depth-JAVA VERSION
来源:互联网 发布:java web开发案例精粹 编辑:程序博客网 时间:2024/06/05 06:09
static ArrayList<LinkedList<Node>> mygetLevelNode(Node root){//initial the linked listArrayList<LinkedList<Node>> result = new ArrayList<LinkedList<Node>>();LinkedList<Node> ll = new LinkedList<Node>();ll.add(root);int level = 0;result.add(level,ll);while(true){//for every row there is a linked list we firstly create it LinkedList<Node> ll2 = new LinkedList(); for(int j = 0;j<result.get(level).size();++j)// level will ++ in the behind; we only get the "former" level{Node n = result.get(level).get(j);if(n.left_child!=null) ll2.add(n.left_child);if(n.right_child!=null) ll2.add(n.right_child);}level++;if(ll2.size()>0){result.add(level,ll2);}else{// if the ll2.size <= 0 that is means we reach the lowest-level-leaves so we break the while(true) loopbreak;}}return result;}
test function ::
ArrayList<LinkedList<Node>> findLinkedLeve = mygetLevelNode(root);for(LinkedList<Node> n:findLinkedLeve){System.out.println("same linked list");for(int i = 0;i<n.size();++i){Node temp = n.get(i);System.out.print(temp.data+" -> ");}}
0 0
- FWNX-creates a linked list of all the nodes at each depth-JAVA VERSION
- Q 4.4 creates a linked list of all the nodes at each depth
- [CrackCode] 4.4 Creates a linked list of all the nodes at each depth of a given tree
- 4 4 Given a binary search tree, design an algorithm which creates a linked list of all the nodes at
- Insert at the front of a linked list
- fwnx - find the middle node in the linked list ~~~
- Retrieving the list of items in a directory all at once
- FWNX-4,.5 JAVA VERSION - SUCCESS OF IN_ORDER_TRAVERSE
- List the maximum or minimum of the elements at each position of two arrays
- Give the common ancestor of all the deepest nodes of a tree
- The realization of a simple single linked list【1.6】
- The realization of a simple single linked list【1.8】
- List All Of The Subsets
- Maximum Depth of Binary Tree(java version)
- FWNX- build a full binary tree via an arrary- java version
- FWNX- build a binary search tree using array - java version <<recursive>>
- Increase the ordinal number at the beginning of each line
- Given a linked list, swap values inside nodes.
- 通过一个例子学习stringstream
- Ubuntu常用命令
- 从明源动力到创新工场这一路走来
- 缓存代理
- CRM上线之路 走上了CRM实施顾问-第104天上班 -第21周
- FWNX-creates a linked list of all the nodes at each depth-JAVA VERSION
- Peterson算法
- SSH整合(二)-Spring整合Hibernate
- Lamport面包店算法
- 临界区
- 2013年度总结
- SMP
- Symmetric multiprocessing
- Introdution to 3D Game Programming With DirectX11 第2章 习题解答