标签:
1 function insert(data) 2 { 3 var newNode = new Node(data,null,null); 4 var parent; 5 var current; 6 if(this.root == null) 7 { 8 this.root = newNode; 9 } 10 else 11 { 12 current = this.root; 13 while(1) 14 { 15 parent = current; 16 if(data<current.data) 17 { 18 current = current.left; 19 if(current == null) 20 { 21 parent.left = newNode; 22 break; 23 } 24 } 25 else 26 { 27 current = current.right; 28 if(current== null) 29 { 30 parent.right = newNode; 31 break; 32 } 33 } 34 } 35 } 36 }
标签:
原文地址:http://www.cnblogs.com/Fadinglemon/p/4235190.html