Binary Tree Task (HL only)

Create a BinaryTree class in Java. It should be a binary search tree with integers increasing from left to right.

You will need to create a Node class with a left and right child and an integer data field.

The binary tree will need the methods:

  • add(int)
  • preOrderPrint()
  • inOrderPrint()
  • postOrderPrint()

Deletion is hard so I won’t ask you to code it, but try to work out what the problem with deletion is.

Create a BinaryTreeDemo class that instantiates a BinaryTree object and populates it with random numbers. Call the print methods to check that it’s all working.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s