binary-search-tree

    0热度

    5回答

    我很难计算给定BST的深度总和[根的所有孩子的各个深度的总和]。我有树的节点总数,我正在计算树的平均深度,需要我有这个深度和。 递归和我不相处得很好..我发现这个问题非常困难。如果可能,我希望看到一个递归解决方案。 注: 我已经创建存取Node.getLeft()和Node.getRight()

    1热度

    2回答

    我对C很陌生,我试图在C中实现一个二叉树,它将存储一个数字和一个字符串,然后将它们打印出来,例如, 1 : Bread 2 : WashingUpLiquid etc. 我到目前为止的代码是: #include <stdio.h> #include <stdlib.h> #define LENGTH 300 struct node { int data; char * defi

    1热度

    2回答

    我不知道如何使用GTree(来自GLib)来存储数据?使用g_tree_insert例程插入GTree的每个新值都会覆盖前一个值! GTree *tree; //init tree = g_tree_new(g_str_equal); //"g_str_equal" is a GLib default compare func //... for(i = 0; i < 100; ++i)

    5热度

    2回答

    我是一个Python家伙。学习C语言,我一直试图在C中实现二叉搜索树。我写下了代码,并且我一直试着从几个小时,但不能按预期得到输出。请帮忙! 请纠正我。 #include<stdlib.h> #include<stdio.h> typedef int ElementType; typedef struct TreeNode { ElementType element;

    1热度

    5回答

    这应该是遍历一个BST并删除每个节点,包括根节点。然而,最后,我得到了“root还有一个左节点”的消息。为什么并非所有节点都被删除? void deleteTree() { deleteNode(root); if(root->right) cout << "root still has a right node" << endl; if(root->l

    0热度

    1回答

    如何在不使用向下转换或类检查的情况下实现多态二叉搜索树(使用EmptyTree和NonEmptyTree)?

    0热度

    2回答

    if right[x] != NIL then return TREE-MINIMUM(right[x]) y<-p[x] while y!= NIL and x = right[y] do x<-y y<-p[y] return y 我知道什么是“正确的,如果[X] = NIL然后返回树民!”的意思,我已经将它翻译成: if(p->RChild) return

    1热度

    1回答

    我试图做递归..父母的整数变量就像我,符合公式2*i +1为leftChild的和2*i +2的权利。 void BST::insert(const data &aData) { if (items[Parent].empty) { items[Parent].theData = aData; items[Parent].empty = false;

    1热度

    2回答

    林有点困惑。林想知道如果基于数组的二叉搜索树是这样实现的? void BST::insert(item &items, const data & aData) {//helper function. Parent++; data *new_data = new data(aData); this->insert(*new_data); } // insert

    1热度

    3回答

    以下实施binary search tree (BST)有什么问题?我被告知最好使用指向struct节点的指针作为插入函数的参数。 struct node { int key_value; struct node* left; struct node* right; }; insert(int key, struct node *leaf) { if(leaf == 0)