二叉搜索树与双向链表
public TreeNode Convert(TreeNode pRootOfTree) {
if(null == pRootOfTree){
return null;
}
//使用二叉树中序遍历,然后修改指针
ArrayList<TreeNode> list = new ArrayList();
bianLi(pRootOfTree,list);
for(int i = 0; i < list.size() - 1; i++){
list.get(i).right = list.get(i + 1);
list.get(i + 1).left = list.get(i);
}
return list.get(0);
}
public void bianLi(TreeNode pRootOfTree,ArrayList<TreeNode> list){
if(null == pRootOfTree){
return;
}
if(null !=pRootOfTree.left){
bianLi(pRootOfTree.left,list);
}
list.add(pRootOfTree);
if(null != pRootOfTree.right){
bianLi(pRootOfTree.right,list);
}
}
不开心的一天,又是这绩效,领导拿你唯唯诺诺。