Lab Report # 11 - Binary Tree
Lab Report # 11 - Binary Tree
Lab Report # 11 - Binary Tree
Lab Report # 11
Introduction to Binary Tree
Section-B
SUMITTED TO
Sir Syed Ali Naqi Raza
SUMITTED BY
Armughan Ali (20-SE-039)
Samia Nawaz Yousafzai (20-SE-048)
Hooria Shahbaz (20-SE-042)
struct Root {
int data;
Root* leftChild;
Root* rightChild;
};
class BinaryTree {
public:
Root* creatingTree() {
int data;
Root* temp = new Root;
cout << "\tEnter data: ";
cin >> data;
if (data == -1) {
return 0;
}
temp->data = data;
cout << "\n\tEnter left child of " << data << "\n";
temp->leftChild = creatingTree();
cout << "\n\tEnter right child of " << data << "\n";
temp->rightChild = creatingTree();
return temp;
}
void preorder(Root* root) {
if (root != NULL) {
cout << "\t" << root->data;
preorder(root->leftChild);
preorder(root->rightChild);
}
}
void inorder(Root* root) {
if (root != NULL) {
inorder(root->leftChild);
cout << "\t" << root->data;
inorder(root->rightChild);
}
}
}
return current;
}
delete succ;
return root;
}
}
};
int main() {
BinaryTree binaryTree;
return 0;
}
Output
Conclusion
In this lab, we grabbed the concept of the most powerful data structure and also put this
concept in to practical work by implementing its major functions that are insertion in a
binary tree, deletion in a binary tree, traversing a tree.