C语言实现二叉树-利用二叉树统计单词数目(二)

2015-11-10 13:46:16 · 作者: · 浏览: 40
e * tree) {
? ? if(tree) {
? ? ? ? deltree(tree->left);
? ? ? ? deltree(tree->right);
? ? ? ? free(tree);
? ? }
}


void print_inorder(node * tree) {
? ? if(tree) {
? ? ? ? print_inorder(tree->left);
? ? ? ? printf("[%s\t\t\t]count:[%d]\n",tree->str,tree->count);
? ? ? ? print_inorder(tree->right);
? ? }
}



int main(int argc, char ** argv)
{
? ? node * root;
? ? node * tmp;
? ? //int i;


? ? root = NULL;
? ? /* Inserting nodes into tree */
? ? insert(&root,"hello");
? ? insert(&root,"hey");
? ? insert(&root,"hello");
? ? insert(&root,"ok");
? ? insert(&root,"hey");
? ? insert(&root,"hey");
? ? insert(&root,"hey");



? ? printf("In Order Display\n");
? ? print_inorder(root);



? ? /* Deleting all nodes of tree */


? ? deltree(root);
}


最后运行结果如下:



Discussion


那么这个程序已经完成啦!


还有很多可以优化的,也可以增加更多的功能;


例如,查找特定字符出现的次数;


或者特定字符所出现的行数,等等都可以;


我们会在日后慢慢完善;