CMPT 125 Lecture 15: Lecture 15 Part 4

13 views2 pages

Document Summary

Lecture 15 part 4 void bst_insert(bst_t* tree, int item) if (tree->root == null) tree->root = create_node(item); else. Btnode_t* prev = null; while (current!=null) prev = current; if (current->value > item) current = current->left; else current = current->right; if (prev->value > item) //printf("add %d to left of %d\n", item, prev->value); prev->left = create_node(item); prev->left->parent = prev; else. //printf("add %d to right of %d\n", item, prev->value); prev->right = create_node(item); prev->right->parent = prev; Create a binary search tree from the following list of insertions: List 1: 4, 2, 6, 1, 3 , 5, 7. List 2: 1, 2, 3, 4, 5, 6, 7. List 3: 1, 2, 3, 7, 6, 5, 4. List 4: 1, 7, 2, 6, 3, 5, 4. Write a function that removes a given element from a bst. Step 1: get a pointer to the node we want to remove. Just remove the vertex, and update its parent.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents