binary-search-tree

Modifying Binary Search to Find then Delete

喜你入骨 提交于 2019-12-25 05:00:52
问题 I am very new to programming, and I am working with the C++ language. This is for my homework, and is using binary search trees. What I am trying to do is create a function called find_node, which later then calls a function called delete_node. This is what the teacher gave as a prompt for the find_node function. Prompt from professor: Add void find_node( const T &val ) method to the class Node to find the node that contains val; if you do not find, there is nothing to do if you find it and p

Mirror Binary Search Tree

拜拜、爱过 提交于 2019-12-25 04:59:15
问题 This is a code that given a root of the binary search tree, is to create its mirror. def mirror(root): if root is None: pass else: mirror(root.left) mirror(root.right) temp = root.left root.left = root.right root.right = temp Firstly, is this code right and also is the recursion here supposed to first get to the leaves of the tree first and then switch the references when unwinding? 回答1: It's right, but not very Pythonic. Better to just write def mirror(root): if root is None: return mirror

Search button in DataGridView with textboxchanged

我们两清 提交于 2019-12-25 03:43:14
问题 I want to do search button in DataGridView. I read my data with this code: private void button1_Click_1(object sender, EventArgs e) { FileStream f1 = new FileStream("zapis.dat", FileMode.Open); BinaryReader br = new BinaryReader(f1); int а = 0; while (f1.Position < f1.Length) { string data = br.ReadString(); string sing = br.ReadString(); string avtor = br.ReadString(); string zagl = br.ReadString(); string janr = br.ReadString(); string ezik = br.ReadString(); dataGridView1.Rows.Add(++а,

standard ml make bst out of a list

半腔热情 提交于 2019-12-25 03:32:55
问题 I want to make a function standard ml that takes a list and function and makes a BST out of it. The function's type is: 'a list -> ('a * 'a -> bool) -> 'a tree , but I'm having some problems with it, here are the code I wrote: datatype 'data tree = EMPTY | NODE of 'data tree * 'data * "data tree; fun makeBST [] f = EMPTY | makeBST (x::xs) f = let fun insert EMPTY x = NODE(EMPTY, x, EMPTY) | insert (NODE(left, root, right)) x = if f(x, root) then insert left x else insert right x in makeBST xs

Insert Method in a BinarySearchTree

社会主义新天地 提交于 2019-12-25 03:32:14
问题 Hey i have written some kind of Binary Search Tree, which has a insert method. So it gets a Object to insert, a Char Array and a Integer which gives it the Index to look at. So this is the insert method : public void insert(Buchstabe pBuchstabe,char[] pChar,int pStelle) { if(pBuchstabe==null) return; if(baum.isEmpty()) { baum=new BinaryTree(pBuchstabe); } else if(pStelle <= pChar.length) { if(pChar[pStelle] == '.') { Mybaum lTree=this.getLeftTree(); lTree.insert(pBuchstabe,pChar,pStelle+1);

sort Array before adding to a Binary Search tree Java

霸气de小男生 提交于 2019-12-25 02:02:39
问题 I have an Array of Strings that are in order A-Z. I was wondering the best way to go about sorting them for a balanced binary search tree. My initial thought is to split the array up into the first half and the second half and then sort them individually. Shouldn't I be able to use a recursive way to keep splitting it in half to get the next Node for the tree? I just can't wrap my head around it right now and thought I would ask if any one had any ideas. to lead me in the right direction or

Why do we need to return the head pointer in a BST after inserting node?

喜欢而已 提交于 2019-12-25 01:54:24
问题 #include<stdio.h> #include<stdlib.h> typedef struct BTreeNode BTNode; struct BTreeNode { int value; struct BTreeNode *left_child,*right_child; }; BTNode* insert(int input_value, BTNode **head_node) { BTNode *temp,*head; temp = malloc(sizeof(BTNode)); temp->value = input_value; temp->left_child = NULL; temp->right_child = NULL; head = *head_node; while(1) { if(head == NULL) { head = temp; // break; return head; } if(temp->value > head->value) { if(head->right_child == NULL) { head->right_child

c++ delete specific node with two children from binary search tree

随声附和 提交于 2019-12-24 21:00:16
问题 I'm currently working on a program to handle a BST in c++. I have all of my functions currently working, except removeNode, which deletes a node of given key value in the tree. I think the first two cases work, but the 3rd is giving me trouble. I know the logic of how to delete a node with two children, but the code is not working for me at the moment. Here is node struct node{ int key; node* left; node* right; }; And here is the code for the delete function, with the case of a node with more

Having trouble with a binary search tree remove function

♀尐吖头ヾ 提交于 2019-12-24 15:43:00
问题 I'm attempting to remove a given value from a binary search tree. The function returns 1 if the given value was present, and 0 if it wasn't. I don't think I'm returning values properly. The proper values seem to be removed, but I'm printing a removal message when I shouldn't be, indicating that the function is returning 0 when it shouldn't be. Can anybody help me spot my error? Thanks. /*Remove data from BST pointed to by rootRef, changing root if necessary. * For simplicity's sake, always

Insert node key and value in binary search tree using scheme

こ雲淡風輕ζ 提交于 2019-12-24 13:33:46
问题 I am inserting a key key and a value val into the tree-map t returning a new tree with a node containing the key and the value in the appropriate location. I have this defined: (define (tree-node key value left right)(list key value left right)) (define (get-key tn) (node_key tn)) (define (get-val tn) (node_val tn)) (define (get-left tn) (node_left tn)) (define (get-right tn) (node_right tn)) (define (node_key tn) (list-ref tn 0)) (define (node_val tn) (list-ref tn 1)) (define (node_left tn)