how to convert a list into an avl tree

147 views Asked by At


I need to change my list interface into a avl-tree. I know how a AVL tree works, but still don't get, how to save data in the structure.

Is it neccessary to still keep the ID of my old list items and just link them to the AVL tree?
I am writing a small rpg, where the quests and events are saved in two lists and got different IDs.

This is how I get my items from my list:

public Item getItem(int i) {
  if (i < 0 || i >= length()) {
    throw new IndexOutOfBoundsException(String.format("%d / %d", i, length()));
  }
  if (i <= 0) {
    return firstItem();
  } return next.getItem(--i);
}
0

There are 0 answers