Information

Author(s) Maxime Mawait & Nicolas Rybowski
Deadline Καμία προθεσμία
Submission limit No limitation
Category tags S3, Linked list, Struct, Level 3

Ετικετές

Συνδεθείτε

[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:

s3_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.