Skip to content

Instantly share code, notes, and snippets.

@Tony363
Created January 8, 2022 09:52
Show Gist options
  • Save Tony363/1998929b4db34cbd8204303c6d7ca3ca to your computer and use it in GitHub Desktop.
Save Tony363/1998929b4db34cbd8204303c6d7ca3ca to your computer and use it in GitHub Desktop.
int n_chars, offset = 0;
CBinTreeNode *_buildCBinTree(CBinTreeNode *root, const char *s)
{
char word[10];
if (sscanf(s + offset, "%s%n", word, &n_chars))
offset += n_chars;
else
return NULL;
if (word[0] == '@')
return NULL;
root = createNode(word);
root->left = _buildCBinTree(root->left, s);
root->right = _buildCBinTree(root->right, s);
return root;
}
CBinTree *buildCBinTree(const char *s)
{
CBinTree *tree = (CBinTree *)malloc(sizeof(CBinTree));
tree->root = _buildCBinTree(tree->root, s);
return tree;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment