public class ArrayTree<K> extends Object
Constructor and Description |
---|
ArrayTree(Comparator<K> comparator)
Creates a new instance of AVLTree.
|
ArrayTree(Comparator<K> comparator,
K[] array)
Creates a new instance of AVLTree.
|
Modifier and Type | Method and Description |
---|---|
boolean |
contains(K key)
Tells if a key exist in the array.
|
K |
find(K key)
Find an element in the array.
|
K |
findGreater(K key)
Finds a key higher than the given key.
|
K |
findGreaterOrEqual(K key)
Finds a key higher than the given key.
|
K |
findLess(K key)
Finds a key which is lower than the given key.
|
K |
findLessOrEqual(K key)
Finds a key chich is lower than the given key.
|
K |
get(int position)
Get the element at a given position
|
int |
getAfterPosition(K key)
Find the element position in the array, or the position of the closest greater element in the array.
|
int |
getBeforePosition(K key)
Find the element position in the array, or the position of the closest greater element in the array.
|
Comparator<K> |
getComparator() |
K |
getFirst()
Get the first element in the tree.
|
List<K> |
getKeys() |
K |
getLast()
Get the last element in the tree.
|
int |
getPosition(K key)
Find the element position in the array.
|
K |
insert(K key)
Inserts a key.
|
boolean |
isEmpty()
Tests if the tree is empty.
|
void |
printTree()
Prints the contents of AVL tree in pretty format
|
K |
remove(K key)
Removes a key present in the tree
|
int |
size()
returns the number of nodes present in this tree.
|
String |
toString() |
public ArrayTree(Comparator<K> comparator)
comparator
- the comparator to be used for comparing keyspublic ArrayTree(Comparator<K> comparator, K[] array)
comparator
- the comparator to be used for comparing keysarray
- The array of keyspublic Comparator<K> getComparator()
public K insert(K key)
key
- the item to be inserted, should not be nullpublic K remove(K key)
key
- the value to be removedpublic boolean isEmpty()
public int size()
public void printTree()
public K get(int position)
position
- The position in the treepublic K getFirst()
public K getLast()
public K findGreater(K key)
key
- the key to findpublic K findGreaterOrEqual(K key)
key
- the keypublic K findLess(K key)
key
- the keypublic K findLessOrEqual(K key)
key
- the keypublic K find(K key)
key
- the key to findpublic int getPosition(K key)
key
- the key to findpublic int getAfterPosition(K key)
key
- the key to findpublic int getBeforePosition(K key)
key
- the key to findpublic boolean contains(K key)
key
- The key to look forCopyright © 2003–2020 The Apache Software Foundation. All rights reserved.