This project is a C++ library which consists of various functions and features to help and simplify operations performed on a binary tree.
This library i.e
"binarytree.hpp"consists of the following functionality:
1) Pre-defined structure for creating Node of a Binary Tree
2) Serializing a Binary Tree.
3) Deserializing a Binary Tree.
4) Visualizing a Binary Tree.
Let us understand how to use these functions:
To include this library in your project:
i) Download the project
ii) Move the file in your project directory and include it using
#include "binarytree.hpp"OR Include it by providing a valid path to the file
struct TreeNode: This structure represents a node of a binary tree. It consists of
int datathat stores value of the TreeNode and left and right pointer which (if there exists) points to left and right TreeNode or NULL. Below is the graphical representation of a TreeNode.
binarytree.serialize(TreeNode): This function accepts a TreeNode as an input and returns a serialized string of the binary tree provided. The output string is an inorder representation of the binary tree. This simplifies printing output binary tree to the console and it is easier to compare the output.
binarytree.deserialize(s): This function accepts a string as an input and returns a TreeNode consisting of the binary tree. The string should be an inorder representation of the binary tree. This simplifies reading the binary tree from the console.
Example s = "1 2 3 NULL 4 5 6".
binarytree.visualize(TreeNode): This function accepts a TreeNode as an input and displays the provided binary tree. This function helps in visualizing complex binary trees which may contain more than 20 nodes.
Given below is an implementation of this library. This file is included in the project directory for reference.
Submitted by Siddharth Vinayak Bawane (Sidb07)
Download packets of source code on Coders Packet