[S3] Simple Binary Search Tree

For this task, you will implement a simple binary search on an existing binary tree. A binary tree has the following structure:

BST/bst.png

This binary tree is composed of nodes implemented using the following structure.

/*
* Node has a value, @value, and two children, @left and @right.
* All the children of @left and itself have a smaller value than the node and all the children of @right and itself have a larger value than node
*/
typedef struct node{
    int value;
    struct node* left; // to smaller values
    struct node* right; // to larger values
} node_t;

The binary tree itself is defined as follows.

typedef struct bt{
    struct node* root;
} bt_t;

Question 1: Function contains

Write the body of the contains function. If you use subfunctions, write them in the box below with their signature and body.

/*
* Return 1 if there is a node containing @value in @tree and 0 otherwise.
*/
int contains(bt_t* tree, int value){
Question 2: Helpful submethods

Write here the submethods used by the contains method.

Information

Author(s) Maxime Mawait & Nicolas Rybowski
Deadline No deadline
Submission limit No limitation
Category Tags Data structures, S4

Tags

Sign in