This repository contains a clean, beginner-friendly Java implementation of a Binary Tree that supports:
- ✔ Level-order insertion (first empty left or right position)
- ✔ BFS traversal (level-order)
- ✔ DFS traversals (Inorder, Preorder, Postorder)
- ✔ Custom queue implementation using linked nodes
- ✔ Menu-based user interaction (switch-case based)
No inbuilt Java collections (like LinkedList, Queue, or ArrayList) were used.
Everything is implemented manually for learning core data structures.
A simple binary tree where nodes are inserted top-to-bottom, left-to-right, similar to a complete binary tree.
The program finds the first available position using a custom queue.
Example tree when inserting: 10, 20, 30, 40, 50:
10
/
20 30
/
40 50
Prints nodes in level-order using the same queue logic.
- Inorder: Left → Root → Right
- Preorder: Root → Left → Right
- Postorder: Left → Right → Root
BinaryTreeApp.java
├── Node class
├── BinaryTree class
│ ├── insert()
│ ├── bfs()
│ ├── inorder()
│ ├── preorder()
│ └── postorder()
└── NodeQueue class (custom queue)
- Clone the repository:
git clone https://github.com/your-username/binary-tree-level-order-java.git
2. Compile:
javac BinaryTreeApp.java
3. Run:
java BinaryTreeApp
🧪 Example Input/Output
Insert nodes:
> 10 20 30 40 50
BFS:
10 20 30 40 50
Inorder:
40 20 50 10 30
📘 Learning Goals
-This project helps you understand:
-How binary trees work internally
-How level-order insertion operates
-How BFS differs from DFS
-How queues enable traversal
-Why custom data structures matter
-Perfect for Data Structure courses, assignments, and interview prep.
📄 License
This project is open-source under the MIT License.
✨ Author
MD Safiul Karim
ID: 2301022
Program: Bachelor of Science Internet of Things & Robotics Engineering
Department of Internet of Things & Robotics Engineering
Session: 2023-24
University of Frontier Technology, Bangladesh
Feel free to use or modify this code for learning or educational purposes.