Thông tin

Tác giả Maxime Mawait & Nicolas Rybowski
Hạn chót Không có hạn chót
Giới hạn nộp bài Không có giới hạn
Các tag chuyên mục S3, Linked list, Struct, Level 3

Tags

Đăng nhập

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

Câu hỏi 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){
Câu hỏi 2: Helpful submethods

Write here the submethods used by the contains method.