码迷,mamicode.com
首页 > 其他好文 > 详细

bst to dll

时间:2018-08-17 00:42:51      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:from   rect   led   new   exp   roo   span   ESS   str   

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

标签:from   rect   led   new   exp   roo   span   ESS   str   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!