binary-search-tree

    1热度

    1回答

    所以我有一个结构数组,我想变成二叉搜索树。这里是我的代码的样子。 typedef struct Student{ char name[25]; char surname[25]; char Id[8]; double grade; }Student; struct TNode { struct TNode* data; struc

    1热度

    2回答

    这是我想出了插入一个新值到BST代码: class BST(object): def __init__(self, root): self.root = Node(root) def insert(self, new_val): self.__internal_insert(self.root, new_val) def __interna

    1热度

    1回答

    我一直在尝试使用类实现二叉搜索树。每次我尝试编译和运行程序时,程序都会结束。我已经尝试了很多东西,比如让* root公开在main中访问它,这样我就可以更新根目录,但不知何故每次都会变为null。 帮助将不胜感激。 这是我的大学项目。 #include <iostream> using namespace std; class tree; class Node { friend c

    1热度

    1回答

    我有一种方法来查找二进制搜索树(BST)中的下一个中序继任者。 “inorderSuccessor”方法将BST的任何节点作为输入并输出下一个中间继承者。方法和树类的定义如下: class BSTInorderSuccessor{ public static Node inorderSuccessor(Node node) { if (node.right != null) {

    1热度

    2回答

    验证二叉搜索树的常用算法是递归检查每个值是否在有效数字的范围内,并在每个节点上将该范围分成两部分。 一些样品Python来说明该算法(对于非重复的值): def walker(node, low, high): if node is None: return True if not (low < node.data < high): return Fal

    0热度

    3回答

    我是Java的新手,我一直试图实现一个BST,但程序只输出最后插入的值。我对root_node指向哪些方面有错吗?以下是我的源代码Tree.java和Node.java。 Tree.java public class Tree { private Node root_node; public void Tree() { this.root_node = null

    -1热度

    1回答

    我用C语言编写了二叉搜索树,其中的数据是字符串,我尝试键入数据时遇到问题。 错误显示在第14行,我认为root->data是NULL导致它,但我不知道如何解决。 这是我的代码: #include <stdio.h> #include <stdlib.h> #include <string.h> struct Node { Node *parent; Node *left;

    -1热度

    1回答

    我有一个Java编写的BinarySearchTree实现,并且工作正常。在那里,我也有一个函数,用于查找小于参数值的总数。例如:如果作为参数的值是100,我的树有元素10,20,30,40,80,90,99,那么这个函数返回7.我希望这是有道理的。我将此功能命名为numLessthan。执行的代码是在这里:https://gist.github.com/shreezan123/bf41fb892

    0热度

    1回答

    我目前正在研究二叉搜索树的C++实现。一切看起来都很完美,但我的搜索功能给了我很多问题。 BinarySearchTree::node* BinarySearchTree::SEARCH(node* x, int key) { if(root == NULL) { cout << "This is an empty tree." << endl; retur

    1热度

    1回答

    作为Haskell的初学者,我目前正试图让我的头绕BST。目前我正在尝试在树上进行折叠。 这是我到目前为止,但它会产生一个错误。 inorder' :: (b -> a -> b) -> b -> BinaryTree a -> b inorder' _ a myTree = a inorder' fun a (Node left root right) = inorder' fun (fun