Skip to content

Instantly share code, notes, and snippets.

@pgsin
Created May 30, 2020 18:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pgsin/00f31a551e4d65bd2bdc2a5911ebd833 to your computer and use it in GitHub Desktop.
Save pgsin/00f31a551e4d65bd2bdc2a5911ebd833 to your computer and use it in GitHub Desktop.
#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