首页 > 其他 > 详细

bst to dll

时间:2018-08-17 00:23:47      阅读:239      评论:0      收藏:0      [点我收藏+]
bst to dll

NOT TESTED YET 

 public Node head = null;
    public Node prev = null;


    public void inOrder(Node root){
      if(root == null){
        return;
      }
      inOrder(root.left);
      if(prev == null){
        head = root;
      }else{
        prev.right = root;
        root.left = prev;
      }
      prev = root;
      inOrder(root.right);
    }

 return head;







=================

class Solution {
  
    public Node head = null;
    public Node prev = null;

    public Node treeToDoublyList(Node root) {
     
      
      inOrder(root);
      return head;
    }
  
    public void inOrder(Node root){
      if(root == null){
        return;
      }
      inOrder(root.left);
      if(prev == null){
        head = root;
      }else{
        prev.right = root;
        root.left = prev;
      }
      prev = root;
      inOrder(root.right);
    }
}






Global varriable which is defined after the class tag and before Method. so there are two type of Global variable
1. Instace global variable
* public class GolbalVariable{
* public String username;
* public String password;
* }
Explanation : this is called as instance variable . so on instance method you can access directly . suppose if you want to access inside statioc method then create Object of class and access it . if method is static then code to access the variable
* ClassObject obj=new ClassObject();//create class Object from static method
* username;//if username is static 
* obj.username; // if username is instance
1. static global variable
* public class GolbalVariable{
* public static String username;
* public static String password;
* }
Explanation : You can access directly with class Name

 

bst to dll

原文:https://www.cnblogs.com/tobeabetterpig/p/9490878.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!