Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C This is Binary Search Tree. Can anyone tell me how to fix these functions? Don't just rephrase the introduction for each function. #include #include

C

This is Binary Search Tree. Can anyone tell me how to fix these functions?

Don't just rephrase the introduction for each function.

#include

#include "bst.h"

#include "stack.h"

/*

* This structure represents a single node in a BST. In addition to containing

* pointers to its two child nodes (i.e. `left` and `right`), it contains two

* fields representing the data stored at this node. The `key` field is an

* integer value that should be used as an identifier for the data in this

* node. Nodes in the BST should be ordered based on this `key` field. The

* `value` field stores data associated with the key.

*

* You should not modify this structure.

*/

struct bst_node {

int key;

void* value;

struct bst_node* left;

struct bst_node* right;

};

/*

* This structure represents an entire BST. It specifically contains a

* reference to the root node of the tree.

*

* You should not modify this structure.

*/

struct bst {

struct bst_node* root;

};

/*

* This function should allocate and initialize a new, empty, BST and return

* a pointer to it.

*/

struct bst* bst_create() {

struct bst* new_bst = malloc(sizeof(struct bst));

new_bst->root = NULL;

return new_bst;

}

/*

* This function should free the memory associated with a BST. While this

* function should up all memory used in the BST itself, it should not free

* any memory allocated to the pointer values stored in the BST. This is the

* responsibility of the caller.

*

* Params:

* bst - the BST to be destroyed. May not be NULL.

*/

void bst_free(struct bst* bst) {

/*

* FIXME:

*/

return;

}

/*

* This function should return the total number of elements stored in a given

* BST.

*

* Params:

* bst - the BST whose elements are to be counted. May not be NULL.

*/

int bst_size(struct bst* bst) {

/*

* FIXME:

*/

return 0;

}

/*

* This function should insert a new key/value pair into the BST. The key

* should be used to order the key/value pair with respect to the other data

* stored in the BST. The value should be stored along with the key, once the

* right location in the tree is found.

*

* Params:

* bst - the BST into which a new key/value pair is to be inserted. May not

* be NULL.

* key - an integer value that should be used to order the key/value pair

* being inserted with respect to the other data in the BST.

* value - the value being inserted into the BST. This should be stored in

* the BST alongside the key. Note that this parameter has type void*,

* which means that a pointer of any type can be passed.

*/

void bst_insert(struct bst* bst, int key, void* value) {

/*

* FIXME:

*/

return;

}

/*

* This function should remove a key/value pair with a specified key from a

* given BST. If multiple values with the same key exist in the tree, this

* function should remove the first one it encounters (i.e. the one closest to

* the root of the tree).

*

* Params:

* bst - the BST from which a key/value pair is to be removed. May not

* be NULL.

* key - the key of the key/value pair to be removed from the BST.

*/

void bst_remove(struct bst* bst, int key) {

/*

* FIXME:

*/

return;

}

/*

* This function should return the value associated with a specified key in a

* given BST. If multiple values with the same key exist in the tree, this

* function should return the first one it encounters (i.e. the one closest to

* the root of the tree). If the BST does not contain the specified key, this

* function should return NULL.

*

* Params:

* bst - the BST from which a key/value pair is to be removed. May not

* be NULL.

* key - the key of the key/value pair whose value is to be returned.

*

* Return:

* Should return the value associated with the key `key` in `bst` or NULL,

* if the key `key` was not found in `bst`.

*/

void* bst_get(struct bst* bst, int key) {

/*

* FIXME:

*/

return NULL;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft SQL Server 2012 Unleashed

Authors: Ray Rankins, Paul Bertucci

1st Edition

0133408507, 9780133408508

More Books

Students also viewed these Databases questions

Question

find all matrices A (a) A = 13 (b) A + A = 213

Answered: 1 week ago

Question

Determine the roles of spatial layout and functionality.

Answered: 1 week ago

Question

Be familiar with the basic ways to manage capacity.

Answered: 1 week ago