zoukankan      html  css  js  c++  java
  • JZ026二叉搜索树与双向链表

    二叉搜索树与双向链表

    题目描述

    输入一棵二叉搜索树,将该二叉搜索树转换成一个排序的双向链表。要求不能创建任何新的结点,只能调整树中结点指针的指向。

    题目链接: 二叉搜索树与双向链表

    代码

    /**
     * 标题:二叉搜索树与双向链表
     * 题目描述
     * 输入一棵二叉搜索树,将该二叉搜索树转换成一个排序的双向链表。要求不能创建任何新的结点,只能调整树中结点指针的指向。
     * 题目链接:
     * https://www.nowcoder.com/practice/947f6eb80d944a84850b0538bf0ec3a5?tpId=13&&tqId=11179&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking
     */
    public class Jz26 {
    
        private TreeNode pre = null;
        private TreeNode head = null;
    
        public TreeNode convert(TreeNode pRootOfTree) {
            inOrder(pRootOfTree);
            return head;
        }
    
        /**
         * 中序遍历
         *
         * @param node
         */
        private void inOrder(TreeNode node) {
            if (node == null) {
                return;
            }
            inOrder(node.left);
            node.left = pre;
            if (pre != null) {
                pre.right = node;
            }
            pre = node;
            if (head == null) {
                head = node;
            }
            inOrder(node.right);
        }
    
        public static void main(String[] args) {
    
        }
    }
    

    【每日寄语】 悟已往之不谏,知来者之可追。实迷途其未远,觉今是而昨非。

  • 相关阅读:
    自定义input标签输入框
    sys.argv 启动时可以传入变量
    falcon 监控
    wrk 压测工具
    mysql UPDATE和REPLACE
    tesseract识别图片中文字
    centos 查看日志 & 查找文件、目录、内容 & centos查看磁盘使用情况
    压力测试
    tensorflow + scikit-learn
    Pycharm快捷键配置
  • 原文地址:https://www.cnblogs.com/kaesar/p/15691344.html
Copyright © 2011-2022 走看看