0

Ok I'm trying to start my assignment but I have no clue where to start first of all and how the end output would even look like. It's an Algorithm class so he doesn't show us codes or anything that may help coding in Java. We also never dealed with any nodes in the java programming classes before. We're suppose to use an AVL Tree and have find, insert, remove, and inorder traversal methods. My question is mostly how would I output this? All he has ever done was draw the tree so how would this small program be outputted?

Any help on where to start would be helpful also. I just need a jump start and I think I could get the rest. For example is the program suppose to output in some sort of GUI that shows the tree?

user2318083
  • 567
  • 1
  • 8
  • 27

1 Answers1

1

The homework requirement is clear that you need an AVL implementation that has insert, remove, traversal.

So hope this could get you started.

public class AVLTreeNode {
    private int value;
    private AVLTreeNode left;
    private AVLTreeNode right;
    private AVLTreeNode parent;
    //constructor
    //getters/setters
    //required functions
    boolean insert(AVLTreeNode node);
    AVLTreeNode remove(int value);
    AVLTreeNode remove(AVLTreeNode node);
    List<AVLTreeNode> inorderTraversal();
}
F.Z
  • 93
  • 6
  • Thanks! It looks like it can give me a great jump start! May I ask if the "find" method would be similar or the same as the remove? – user2318083 Oct 17 '13 at 05:45
  • 1
    yeah find can be similar to remove, or insert. The signature really depends on what you want to do with the function and what kind of result you need. – F.Z Oct 17 '13 at 05:47
  • I will look into it more, I appreciate your help. – user2318083 Oct 17 '13 at 05:49
  • Making the constructor right now, I was wondering shouldn't those private variables be in the constructor? Or will they work even if they're not inside the constructor class? Also with how I set it up, I have the insert and remove method as insert(AVLTreeNode node, int value) and remove(AVLTreeNode node, int value) which probably should work just as well right? – user2318083 Oct 19 '13 at 20:19