Created
May 30, 2020 18:56
-
-
Save pgsin/00f31a551e4d65bd2bdc2a5911ebd833 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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