# java – inorder traversal algorithm

I’m trying to create a BST and use inorder traversal algorithm. But my inOrder method returns only data of root (8). Need some help.

``````  public static void main(String() args) {
Tree<Integer> tree = new Tree<Integer>();
Node<Integer> root = new Node<>(8);

tree.inOrder(root);// get 8 as a result
}
}
``````
``````public class Tree<T extends Comparable<T>> {
private Node<T> root;

Node<T> node = new Node<>(data);
if (root == null) {
root = node;
} else doInsert(root, node);

}

public void doInsert(Node<T> root, Node<T> node) {
if (node.data.compareTo(root.data) < 0) {
if (root.left == null) {
root.left = node;
} else doInsert(root.left, node);
} else if (root.right == null) {
root.right = node;
} else doInsert(root.right, node);

}
``````
`````` public void inOrder(Node<T> root) {
if (root != null) {
inOrder(root.left);
System.out.print(root.data + " ");
inOrder(root.right);
}
}
``````
``````class Node<T> {
Node<T> left;
Node<T> right;
T data;

public Node(T data) {
this.data = data;

}
}
$$```$$
``````