Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class CompleteTree extends BinaryTree {
- public CompleteTree() {
- super();
- }
- public void insert(Comparable item) {
- if(this.isEmpty()) {
- this.setRoot(new TreeNode(item));
- return;
- }
- TreeNode p = null;
- TreeNode q = this.getRoot();
- while(q != null) {
- p = q;
- if(p.getLeft() == null)
- q = p.getLeft();
- else if(p.getRight() == null)
- q = p.getRight();
- else
- q = p.getLeft();
- }
- p.setValue(new TreeNode(item));
- }
- public void inorder() {
- doInorderTraversal(this.getRoot());
- }
- private void doInorderTraversal(TreeNode t) {
- if(t != null) {
- doInorderTraversal(t.getLeft());
- System.out.print(t.getValue() + " ");
- doInorderTraversal(t.getRight());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement