Lab 9
Lab 9
int value;
TreeNode left;
TreeNode right;
this.value = value;
left = null;
right = null;
package lab9question1;
public BinaryTree() {
size++;
} else {
if (tree[i].value == value) {
return;
if (tree[i].value == value) {
indexToDelete = i;
break;
if (indexToDelete == -1) {
return;
size--;
if (size == 0) {
System.out.println("Tree is empty.");
return;
System.out.println();
//Main Class
package lab9question1;
binaryTree.insert(treeArray[i]);
binaryTree.displayTree();
binaryTree.search(1);
binaryTree.search(8);
binaryTree.delete(7);
binaryTree.displayTree();
Output:
Q2: Write a program which should implement a binary tree using array. Elements of array are
objects of “student” class. “student” class contains attributes (privately defined) reg_no(int),
st_name (string) and cgpa (float). “student” class should also contain member functions
(publicly defined); constructor, input and output functions. User will insert objects of class
“student” array of binary tree, values of attributes of objects will be provided by user.
Program should insert the values using level order insertion technique.
Code:
package lab9question2;
this.capacity = capacity;
this.size = 0;
tree[size++] = student;
} else {
if (size == 0) {
return;
tree[i].output();
}
package lab9question2;
this.regNo = regNo;
this.studentName = stName;
this.cgpa = cgpa;
System.out.println("Reg No: " + regNo + ", Name: " + studentName + ", CGPA: " + cgpa);
return regNo;
return studentName;
return cgpa;
///Main class
package lab9question2;
Student[] students = {
};
tree.insertStudent(s);
tree.displayTree();
Output: