[Solved] Why isn’t std::set just called std::binary_tree? [closed]

Why isn’t std::set just called std::binary_tree? Because Tree doesn’t describe how the interface is used. Set does. std::set does not provide sufficient operations to be used as a general purpose search tree. It only provides an interface to a particular application of a search tree: The representation of a set. Technically the standard doesn’t specify … Read more

[Solved] wrong result in Visual Studio

insert_recursively does not return a value when it goes into else block however you store the returned value (garbage) in right_linker or left_linker anyway. Note that compiler issues a corresponding warning: warning C4715: ‘insert_recursively’: not all control paths return a value 1 solved wrong result in Visual Studio

[Solved] Search function returns the same regardless of item present in the binary search tree

Your code invoke UB. tree_node *root; … c=b.search(root,number); // root is uninitialized To solve this add a new function: class bst { … int search(tree_node * ,int); int search(int v) { return search(root, v); } }; Also in bst::search function: else //if (root != NULL){ Comment this condition if(root->data == data) { // r=”t”; return … Read more

[Solved] TreeNode cannot be cast to java.lang.Comparable?

Your problem is that while the generic parameter of TreeNode is Comparable, the class itself is not. Change this: public static class TreeNode<E extends Comparable<E>> { To this: public static class TreeNode<E extends Comparable<E>> implements Comparable<TreeNode<E>> { Or if you don’t require the generic type to also be Comparable: public static class TreeNode<E> implements Comparable<TreeNode<E>> … Read more