Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#include <bits/stdc++.h>
using namespace std;
struct BinaryTreeNode {
int data;
BinaryTreeNode* left;
BinaryTreeNode* right;
};
BinaryTreeNode* init(int data){
BinaryTreeNode* node = (BinaryTreeNode*)malloc(sizeof(BinaryTreeNode));
node->left = NULL;
node->right = NULL;
node->data = data;
return node;
}
void free(BinaryTreeNode* root){
//TODO
}
bool isLeaf(BinaryTreeNode* node){
return root->left == NULL && root->right == NULL;
}
BinaryTreeNode* adding(BinaryTreeNode* root, int data){
//TODO
return NULL;
}
bool searching(BinaryTreeNode* root, int data){
//TODO
return false;
}
int height(BinaryTreeNode* root){
//TODO
return 0;
}
void printingImpl(BinaryTreeNode* node){
if (node == NULL){
return;
}
if(isLeaf(node)){
cout << node->data;
return;
}
cout << "(";
printingImpl(node->left);
cout << ";";
printingImpl(node->right);
cout << "):" << node->data;
}
void printing(BinaryTreeNode* root){
printingImpl(root);
cout << endl;
}
int main(){
int n, x;
cin >> n;
BinaryTreeNode* root = NULL;
for(int i=0; i<n; i++){
cin >> x;
root = adding(root, x);
}
printing(root);
free(root);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.