标签:null traversal node http rsa public 搜索 stat 入栈
public class Solution {
public static TreeNode Convert(TreeNode pRootOfTree) {
TreeNode p = pRootOfTree;
TreeNode q = null;
if(p!=null){
LinkedList<TreeNode> list = new LinkedList<>();
list.push(p);//根结点入栈
while(p.left!=null){
p = p.left;
list.push(p);
}
TreeNode s = p;
while(!list.isEmpty()){
p = (TreeNode)list.pop();//最左结点
if(q == null){
q = p;
}
else{
q.right = p;
p.left = q;
q = p;
}
if(p.right != null){
list.push(p.right);
p = p.right;
while(p.left!=null){
p = p.left;
list.push(p);
}
}
}
return s;
}
return null;
}
}
https://en.wikipedia.org/wiki/Tree_traversal#Iterative_Traversal
标签:null traversal node http rsa public 搜索 stat 入栈
原文地址:https://www.cnblogs.com/dyq19/p/10549710.html