public int height(){
return Math.max(leftnull?0:left.height(),rightnull?0:right.height())+1;
}
public void leftRotate(){
Node1 newNode=new Node1(no);
newNode.left=left;
newNode.right=this.right.left;
no=this.right.no;
this.right=this.right.right;
this.left=newNode;
}
public void rightRotate(){
Node1 newNode=new Node1(no);
newNode.right=right;
newNode.left=this.left.right;
no=this.left.no;
left=left.left;
this.right=newNode;
}
public void adjust(){
if(this.left.height()-this.right.height()>1){
if(this.left!=null&&this.left.right.height()-this.left.left.height()>1){
this.left.leftRotate();
this.rightRotate();
}
else{
rightRotate();
}
}
if(this.right.height()-this.left.height()>1){
if(this.right!=null&&this.right.left.height()-this.right.right.height()>1){
this.right.rightRotate();
this.leftRotate();
}
else{
leftRotate();
}
}
}
public int height(){
return Math.max(left==null?0:left.height(),right==null?0:right.height())+1;
}
public void leftRotate(){
Node1 newNode=new Node1(no);
newNode.left=left;
newNode.right=this.right.left;
no=this.right.no;
this.right=this.right.right;
this.left=newNode;
}
public void rightRotate(){
Node1 newNode=new Node1(no);
newNode.right=right;
newNode.left=this.left.right;
no=this.left.no;
left=left.left;
this.right=newNode;
}
public void adjust(){
if(this.left.height()-this.right.height()>1){
if(this.left!=null&&this.left.right.height()-this.left.left.height()>1){
this.left.leftRotate();
this.rightRotate();
}
else{
rightRotate();
}
}
if(this.right.height()-this.left.height()>1){
if(this.right!=null&&this.right.left.height()-this.right.right.height()>1){
this.right.rightRotate();
this.leftRotate();
}
else{
leftRotate();
}
}
}