-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAVLnode.java
More file actions
executable file
·39 lines (32 loc) · 1.64 KB
/
AVLnode.java
File metadata and controls
executable file
·39 lines (32 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//package calculatenr;
public class AVLnode<K,V> implements Position<K,V> {
private AVLnode<K,V> parent; // reference to the parent node
private AVLnode<K,V> left; // reference to the left child
private AVLnode<K,V> right; // reference to the right child
private DictEntry<K,V> entry; // reference to the entry stored at the node
private int height; // height of the node for checking balance-height property
public AVLnode(DictEntry<K,V> inputEntry, AVLnode<K,V> inputParent, AVLnode<K,V> inputLeft, AVLnode<K,V> inputRight)
{
entry = inputEntry;
parent = inputParent;
left = inputLeft;
right = inputRight;
height = 0;
if (left != null ) height = Math.max(height,1+left.getHeight());
if (right != null ) height = Math.max(height,1+right.getHeight());
}
public AVLnode<K,V> parent(){ return parent;}
public AVLnode<K,V> left() {return left;}
public AVLnode<K,V> right() {return right;}
public int getHeight () { return height; }
public DictEntry<K,V> getEntry() { return entry; }
public void setParent(AVLnode<K,V> newParent){ parent = newParent; }
public void setLeft(AVLnode<K,V> newLeft) {left = newLeft;}
public void setRight(AVLnode<K,V> newRight) { right = newRight; }
public void setEntry(DictEntry<K,V> newEntry) { entry = newEntry; }
public DictEntry<K,V> element(){return entry;}
public void resetHeight() throws AVLTreeException{
if ( left == null || right == null ) throw new AVLTreeException("Attempt to update height for external node ");
height = 1+Math.max(left.getHeight(),right.getHeight());
}
}