You are on page 1of 41

Bắt đầu vào lúc Thứ Năm, 7 tháng 3 2024, 1:25 PM

Trạng thái Đã xong


Kết thúc lúc Thứ Năm, 14 tháng 3 2024, 7:09 PM
Thời gian thực 7 Các ngày 5 giờ
hiện
Điểm 8,00/8,00
Điểm 10,00 trên 10,00 (100%)


Câu hỏi 1
Đúng

Đạt điểm 1,00 trên 1,00

In this question, you have to perform add and delete on binary sear

- When deleting a node which still have 2 children, take the inorder
that node) to replace it.

- When adding a node which has the same value as parent node, a
Your task is to implement two functions: add and deleteNode. You c
task.


#include <iostream>
#include <string>
#include <sstream>
using namespace std;
#define SEPARATOR "#<ab@17943918#@>#"
template<class T>
class BinarySearchTree
{
public:
class Node;
private:
Node* root;
public:
BinarySearchTree() : root(nullptr) {}
~BinarySearchTree()
{
// You have to delete all Nodes in BinaryTree. However in th
}

//Helping function

void add(T value){


//TODO
}

void deleteNode(T value){


//TODO
}
string inOrderRec(Node* root) {
stringstream ss;
if (root != nullptr) {
ss << inOrderRec(root->pLeft);
ss << root->value << " "; 
ss << inOrderRec(root->pRight);
}
return ss.str();
}
string inOrder(){
return inOrderRec(this->root);
}

class Node
{
private:
T value;
Node* pLeft, * pRight;
friend class BinarySearchTree<T>;
public:
Node(T value) : value(value), pLeft(NULL), pRight(NULL) {}
~Node() {}
};
};

For example:

Test Result

BinarySearchTree<int> bst; 2 10
bst.add(9);
bst.add(2);
bst.add(10);
bst.deleteNode(9);
cout << bst.inOrder();


Test Result

BinarySearchTree<int> bst; 2 8 9 10
bst.add(9); 2 8 10 11
bst.add(2);
bst.add(10);
bst.add(8);
cout << bst.inOrder()<<endl;
bst.add(11);
bst.deleteNode(9);
cout << bst.inOrder();

Answer: (penalty regime: 5, 10, 15, ... %)

Reset answer

1 ▼ Node* addRecursive(Node* node, T value) {


2 ▼ if (node == nullptr) {
3 node = new Node(value);
4 ▼ } else if (value < node->value) {
5 node->pLeft = addRecursive(node->pLeft, value
6 ▼ } else if (value > node->value) {
7 node->pRight = addRecursive(node->pRight, val
8 ▼ } else { // Equal value goes to left subtree
9 node->pLeft = addRecursive(node->pLeft, value
10 }
11 return node;
12 }
13
14 ▼ Node* findInorderSuccessor(Node* node) {
15 Node* current = node;
16 ▼ while (current && current->pLeft != nullptr) {
17 current = current->pLeft; 
18 }
19 return current;
20 }
21
22 ▼ Node* deleteNodeRecursive(Node* node, T value) {
23 if (node == nullptr) return node;
24
25 ▼ if (value < node->value) {
26 node->pLeft = deleteNodeRecursive(node->pLeft
27 ▼ } else if (value > node->value) {
28 node->pRight = deleteNodeRecursive(node->pRig
29 ▼ } else {
30 ▼ if (node->pLeft == nullptr) {
31 Node* temp = node->pRight;
32 delete node;
33 return temp;
34 ▼ } else if (node->pRight == nullptr) {
35 Node* temp = node->pLeft;
36 delete node;
37 return temp;
38 }
39
40 Node* temp = findInorderSuccessor(node->pRigh
41 node->value = temp->value;
42 node->pRight = deleteNodeRecursive(node->pRig
43 }
44 return node;
45 }
46
47 public:
48 ▼ void add(T value) {
49 root = addRecursive(root, value);
50 }
51
52 ▼ void deleteNode(T value) {
53 root = deleteNodeRecursive(root, value);
54 }


Test Expected Got

 BinarySearchTree<int> bst; 2 10 2 10 
bst.add(9);
bst.add(2);
bst.add(10);
bst.deleteNode(9);
cout << bst.inOrder();

 BinarySearchTree<int> bst; 2 8 9 10 2 8 9 10 
bst.add(9); 2 8 10 11 2 8 10 11
bst.add(2);
bst.add(10);
bst.add(8);
cout << bst.inOrder()<<endl;
bst.add(11);
bst.deleteNode(9);
cout << bst.inOrder();

Passed all tests! 

Đúng
Marks for this submission: 1,00/1,00.


Câu hỏi 2
Đúng

Đạt điểm 1,00 trên 1,00

Class BSTNode is used to store a node in binary search tree, described


class BSTNode {
public:
int val;
BSTNode *left;
BSTNode *right;
BSTNode() {
this->left = this->right = nullptr;
}
BSTNode(int val) {
this->val = val;
this->left = this->right = nullptr;
}
BSTNode(int val, BSTNode*& left, BSTNode*& right) {
this->val = val;
this->left = left;
this->right = right;
}
};

Where val is the value of node, left and right are the pointers to th
repeated value is inserted to the tree, it will be inserted to the left su
Also, a static method named createBSTree is used to create the bina
left-to-right and repeatedly calling addNode method on the root node
example: 
int arr[] = {0, 10, 20, 30};
auto root = BSTNode::createBSTree(arr, arr + 4);
is equivalent to
auto root = new BSTNode(0);
root->addNode(10);
root->addNode(20);
root->addNode(30);

Request: Implement function:

vector<int> levelAlterTraverse(BSTNode* root);


Where root is the root node of given binary search tree (this tree has
returns the values of the nodes in each level, alternating from going
Example:
Given a binary search tree in the following:

In the first level, we should traverse from left to right (order: 3) a


left (order: 4, 0). After traversing all the nodes, the result should be [
Note: In this exercise, the libraries iostream, vector, stack, queue, algori
write helper functions; however, you are not allowed to use other lib
For example:

Test

int arr[] = {0, 3, 5, 1, 2, 4};


BSTNode* root = BSTNode::createBSTree(arr, arr + sizeof(arr)/sizeof
printVector(levelAlterTraverse(root));
BSTNode::deleteTree(root);

Answer: (penalty regime: 0, 0, 0, 5, 10, ... %)

Reset answer

1 ▼ vector<int> levelAlterTraverse(BSTNode* root) {


2 vector<int> result;
3 if (!root) return result;
4
5 queue<BSTNode*> nodesQueue;
6 nodesQueue.push(root);
7 bool leftToRight = true;
8
9 ▼ while (!nodesQueue.empty()) {
10 int levelSize = nodesQueue.size();
11 vector<int> level(levelSize);
12
13 ▼ for (int i = 0; i < levelSize; ++i) {
14 BSTNode* node = nodesQueue.front();
15 nodesQueue.pop();
16
17 int index = leftToRight ? i : (levelSize - 1
18 level[index] = node->val;
19
20 if (node->left) nodesQueue.push(node->left);
21 if (node->right) nodesQueue.push(node->right)
22 }

23
24 leftToRight = !leftToRight;
25
26 ▼ for (int val : level) {
27 result.push_back(val);
28 }
28 }
29 }
30
31 return result;
32 }
33

Test

 int arr[] = {0, 3, 5, 1, 2, 4};


BSTNode* root = BSTNode::createBSTree(arr, arr +
sizeof(arr)/sizeof(int));
printVector(levelAlterTraverse(root));
BSTNode::deleteTree(root);

Passed all tests! 

Đúng
Marks for this submission: 1,00/1,00.


Câu hỏi 3
Đúng

Đạt điểm 1,00 trên 1,00

Class BSTNode is used to store a node in binary search tree, described


class BSTNode {
public:
int val;
BSTNode *left;
BSTNode *right;
BSTNode() {
this->left = this->right = nullptr;
}
BSTNode(int val) {
this->val = val;
this->left = this->right = nullptr;
}
BSTNode(int val, BSTNode*& left, BSTNode*& right) {
this->val = val;
this->left = left;
this->right = right;
}
};

Where val is the value of node, left and right are the pointers to th
repeated value is inserted to the tree, it will be inserted to the left su
Also, a static method named createBSTree is used to create the bina
left-to-right and repeatedly calling addNode method on the root node
example: 
int arr[] = {0, 10, 20, 30};
auto root = BSTNode::createBSTree(arr, arr + 4);
is equivalent to
auto root = new BSTNode(0);
root->addNode(10);
root->addNode(20);
root->addNode(30);

Request: Implement function:

int kthSmallest(BSTNode* root, int k);


Where root is the root node of given binary search tree (this tree has
This function returns the k-th smallest value in the tree.
Example:
Given a binary search tree in the following:

With k = 2, the result should be 1.

Note: In this exercise, the libraries iostream, vector, stack, queue


, algori
can write helper functions; however, you are not allowed to use oth

For example:
Test

int arr[] = {6, 9, 2, 13, 0, 20};


int k = 2;
BSTNode* root = BSTNode::createBSTree(arr, arr + sizeof(arr)/sizeof
cout << kthSmallest(root, k);
BSTNode::deleteTree(root);

Answer: (penalty regime: 0, 0, 0, 5, 10, ... %)

Reset answer

1 ▼ void inOrderFind(BSTNode* node, int& k, int& result) {


2 if (node == nullptr || k <= 0) return;
3
4 inOrderFind(node->left, k, result);
5
6 k--;
7 ▼ if (k == 0) {
8 result = node->val;
9 return;
10 }
11
12 inOrderFind(node->right, k, result);
13 }
14
15 ▼ int kthSmallest(BSTNode* root, int k) {
16 int result = -1;
17 inOrderFind(root, k, result);
18 return result;
19 }
20

Test

 int arr[] = {6, 9, 2, 13, 0, 20};


int k = 2;
BSTNode* root = BSTNode::createBSTree(arr, arr + sizeof(arr)/
cout << kthSmallest(root, k);
BSTNode::deleteTree(root);

Passed all tests! 

Đúng
Marks for this submission: 1,00/1,00.


Câu hỏi 4
Đúng

Đạt điểm 1,00 trên 1,00

Class BTNode is used to store a node in binary search tree, de


class BTNode {
public:
int val;
BTNode *left;
BTNode *right;
BTNode() {
this->left = this->right = NULL;
}
BTNode(int val) {
this->val = val;
this->left = this->right = NULL;
}
BTNode(int val, BTNode*& left, BTNode*& right) {
this->val = val;
this->left = left;
this->right = right;
}
};

Where val is the value of node (non-negative integer), left an


and right node of it, respectively.

Also, a static method named createBSTree is used to create th
argument array left-to-right and repeatedly calling addNode me
into the correct position. For example:
int arr[] = {0, 10, 20, 30};
auto root = BSTNode::createBSTree(arr, arr + 4);

is equivalent to
auto root = new BSTNode(0);
root->addNode(10);
root->addNode(20);
root->addNode(30);

Request: Implement function:

int rangeCount(BTNode* root, int lo, int hi);


Where root is the root node of given binary search tree (this tre
and hi are 2 positives integer and lo ≤ hi. This function returns
between [lo, hi] in this binary search tree.
More information:
- If a node has val which is equal to its ancestor's, it is in t

Example:

Given a binary search tree in the following:

With lo=5, hi=10, all the nodes satisfied are node 9, 7, 8;


Note: In this exercise, the libraries iostream, stack, queue, utility
write helper functions; however, you are not allowed to use ot

For example:

Test

int value[] = {3,2,9,7,12,4,8};


int lo = 5, hi = 10;
BTNode* root = BTNode::createBSTree(value, value + sizeof(value)/si
cout << rangeCount(root, lo, hi);

int value[] = {1167,2381,577,2568,124,1519,234,1679,2696,2359};


int lo = 500, hi = 2000;
BTNode* root = BTNode::createBSTree(value, value + sizeof(value)/si
cout << rangeCount(root, lo, hi);

Answer: (penalty regime: 0 %)

Reset answer

1 ▼ int rangeCount(BTNode* node, int lo, int hi) {


2 ▼ if (node == nullptr) {
3 return 0;
4 }
5
6 ▼ if (node->val < lo) {
7 return rangeCount(node->right, lo, hi);
8 ▼ } else if (node->val > hi) {
9 return rangeCount(node->left, lo, hi);
10 ▼ } else {

11 return 1 + rangeCount(node->left, lo, hi) + range
12 }
13 }
14

Test

 int value[] = {3,2,9,7,12,4,8};


int lo = 5, hi = 10;
BTNode* root = BTNode::createBSTree(value, value + sizeof(val
cout << rangeCount(root, lo, hi);

 int value[] = {1167,2381,577,2568,124,1519,234,1679,2696,2359


int lo = 500, hi = 2000;
BTNode* root = BTNode::createBSTree(value, value + sizeof(val
cout << rangeCount(root, lo, hi);

Passed all tests! 

Đúng
Marks for this submission: 1,00/1,00.


Câu hỏi 5
Đúng

Đạt điểm 1,00 trên 1,00

Class BSTNode is used to store a node in binary search tree, described


class BSTNode {
public:
int val;
BSTNode *left;
BSTNode *right;
BSTNode() {
this->left = this->right = nullptr;
}
BSTNode(int val) {
this->val = val;
this->left = this->right = nullptr;
}
BSTNode(int val, BSTNode*& left, BSTNode*& right) {
this->val = val;
this->left = left;
this->right = right;
}
};

Where val is the value of node, left and right are the pointers to th
repeated value is inserted to the tree, it will be inserted to the left su

Also, a static method named createBSTree is used to create the bina


left-to-right and repeatedly calling addNode method on the root node
example: 
int arr[] = {0, 10, 20, 30};
auto root = BSTNode::createBSTree(arr, arr + 4);
is equivalent to
auto root = new BSTNode(0);
root->addNode(10);
root->addNode(20);
root->addNode(30);

Request: Implement function:

int singleChild(BSTNode* root);


Where root is the root node of given binary search tree (this tree has
returns the number of single children in the tree.
More information:

- A node is called a single child if its parent has only one child
Example:
Given a binary search tree in the following:

There are 2 single children: node 2 and node 3.


Note: In this exercise, the libraries iostream and using namespace
 std a
you are not allowed to use other libraries.
For example:
Test

int arr[] = {0, 3, 5, 1, 2, 4};


BSTNode* root = BSTNode::createBSTree(arr, arr + sizeof(arr)/sizeof
cout << singleChild(root);
BSTNode::deleteTree(root);

Answer: (penalty regime: 0, 0, 0, 5, 10, ... %)

Reset answer

1 ▼ int countSingleChild(BSTNode* node) {


2 ▼ if (node == nullptr) {
3 return 0;
4 }
5
6 int count = 0;
7 if ((node->left != nullptr && node->right == nullptr)
8 ▼ (node->left == nullptr && node->right != nullptr)
9 count += 1;
10 }
11 count += countSingleChild(node->left);
12 count += countSingleChild(node->right);
13
14 return count;
15 }
16
17 ▼ int singleChild(BSTNode* root) {
18 return countSingleChild(root);
19 }
20


Test

 int arr[] = {0, 3, 5, 1, 2, 4};


BSTNode* root = BSTNode::createBSTree(arr, arr + sizeof(arr)/
cout << singleChild(root);
BSTNode::deleteTree(root);

Passed all tests! 

Đúng
Marks for this submission: 1,00/1,00.


Câu hỏi 6
Đúng

Đạt điểm 1,00 trên 1,00

Class BSTNode is used to store a node in binary search tree, described

class BSTNode {
public:
int val;
BSTNode *left;
BSTNode *right;
BSTNode() {
this->left = this->right = nullptr;
}
BSTNode(int val) {
this->val = val;
this->left = this->right = nullptr;
}
BSTNode(int val, BSTNode*& left, BSTNode*& right) {
this->val = val;
this->left = left;
this->right = right;
}
};

Where val is the value of node, left and right are the pointers to th
repeated value is inserted to the tree, it will be inserted to the left su

Also, a static method named createBSTree is used to create the bina


left-to-right and repeatedly calling addNode method on the root node
example: 
int arr[] = {0, 10, 20, 30};
auto root = BSTNode::createBSTree(arr, arr + 4);
is equivalent to
auto root = new BSTNode(0);
root->addNode(10);
root->addNode(20);
root->addNode(30);

Request: Implement function:

BSTNode* subtreeWithRange(BSTNode* root, int lo, int hi);


Where root is the root node of given binary search tree (this tree has
returns the binary search tree after deleting all nodes whose values
Example:

Given a binary search tree in the following:

With lo = 7 and hi = 10, the result should be:


Note: In this exercise, the libraries iostream and using namespace std a
you are not allowed to use other libraries.

For example:

Test

int arr[] = {0, 3, 5, 1, 2, 4};


int lo = 1, hi = 3;
BSTNode* root = BSTNode::createBSTree(arr, arr + sizeof(arr)/sizeof
root = subtreeWithRange(root, lo, hi);
BSTNode::printPreorder(root);
BSTNode::deleteTree(root);

Answer: (penalty regime: 0, 0, 0, 5, 10, ... %)

Reset answer

1 ▼ BSTNode* deleteOutsideRange(BSTNode* node, int lo, int hi


2 if (node == nullptr) return nullptr;
3
4 node->left = deleteOutsideRange(node->left, lo, hi);
5 node->right = deleteOutsideRange(node->right, lo, hi)
6 
7 ▼ if (node->val < lo) {
8 BSTNode* rightChild = node->right;
9 delete node;
10 return rightChild;
11 ▼ } else if (node->val > hi) {
11 ▼ } else if (node >val > hi) {
12 BSTNode* leftChild = node->left;
13 delete node;
14 return leftChild;
15 }
16 return node;
17 }
18
19 ▼ BSTNode* subtreeWithRange(BSTNode* root, int lo, int hi)
20 return deleteOutsideRange(root, lo, hi);
21 }
22

Test

 int arr[] = {0, 3, 5, 1, 2, 4};


int lo = 1, hi = 3;
BSTNode* root = BSTNode::createBSTree(arr, arr + sizeof(arr)/
root = subtreeWithRange(root, lo, hi);
BSTNode::printPreorder(root);
BSTNode::deleteTree(root);

Passed all tests! 

Đúng
Marks for this submission: 1,00/1,00.


Câu hỏi 7
Đúng

Đạt điểm 1,00 trên 1,00

Given class BinarySearchTree, you need to finish method find(i) to check whe
calculate sum of all all elements v in the tree that has value greater than or equ


#include <iostream>
#include <string>
#include <sstream>

using namespace std;

template<class T>
class BinarySearchTree
{
public:
class Node;

private:
Node* root;

public:
BinarySearchTree() : root(nullptr) {}
~BinarySearchTree()
{
// You have to delete all Nodes in BinaryTree. However in th
}

class Node
{
private:
T value;
Node* pLeft, * pRight;
friend class BinarySearchTree<T>;

public:
Node(T value) : value(value), pLeft(NULL), pRight(NULL) {}
~Node() {}
}; 
Node* addRec(Node* root, T value);
void add(T value) ;
// STUDENT ANSWER BEGIN
// STUDENT ANSWER END
};

For example:

Test Result

BinarySearchTree<int> bst; 1
for (int i = 0; i < 10; ++i) { 10
bst.add(i);
}
cout << bst.find(7) << endl;
cout << bst.sum(0, 4) << endl

Answer: (penalty regime: 5, 10, 15, ... %)

Reset answer

1 ▼ bool find(Node* node, T i) {


2 if (node == nullptr) return false; // Base case: valu
3 if (node->value == i) return true; // Value found
4 if (node->value > i) return find(node->pLeft, i); //
5 return find(node->pRight, i); // Search right subtree
6 }
7
8 ▼ bool find(T i) {
9 return find(root, i);
10 }
11 ▼ T sum(Node* node, T l, T r) {
12 if (node == nullptr) return 0;
13 ▼ if (node->value >= l && node->value <= r) {
14 return node->value + sum(node->pLeft, l, r) + sum
15 }

16 ▼ else if (node->value < l) {
17 return sum(node->pRight, l, r);
18 }
19 return sum(node->pLeft, l, r);
20 }
21 T (T l T ) {
21 ▼ T sum(T l, T r) {
22 return sum(root, l, r);
23 }
24

Test

 BinarySearchTree<int> bst;
for (int i = 0; i < 10; ++i) {
bst.add(i);
}
cout << bst.find(7) << endl;
cout << bst.sum(0, 4) << endl

 int values[] = { 66,60,84,67,21,45,62,1,80,35 };


BinarySearchTree<int> bst;
for (int i = 0; i < 10; ++i) {
bst.add(values[i]);
}

cout << bst.find(5) << endl;


cout << bst.sum(10, 40);

 int values[] = { 38,0,98,38,99,67,19,70,55,6 };


BinarySearchTree<int> bst;
for (int i = 0; i < 10; ++i) {
bst.add(values[i]);
}

cout << bst.find(5) << endl;


cout << bst.sum(10, 40); 
Test

 int values[] = { 34,81,73,48,66,91,19,84,78,79 };


BinarySearchTree<int> bst;
for (int i = 0; i < 10; ++i) {
bst.add(values[i]);
}

cout << bst.find(5) << endl;


cout << bst.sum(10, 40);

 int values[] = { 94,61,75,36,34,58,62,74,54,90 };


BinarySearchTree<int> bst;
for (int i = 0; i < 10; ++i) {
bst.add(values[i]);
}

cout << bst.find(34) << endl;


cout << bst.sum(10, 40);

 int values[] = { 32,0,2,84,34,78,70,60,95,71,26,62,0,22,9


BinarySearchTree<int> bst;
for (int i = 0; i < 15; ++i) {
bst.add(values[i]);
}

cout << bst.find(34) << endl;


cout << bst.sum(10, 40);

 int values[] = { 53,24,32,40,80,47,81,88,42,29,31,91,77,7


BinarySearchTree<int> bst;
for (int i = 0; i < 15; ++i) {
bst.add(values[i]);
} 

cout << bst.find(34) << endl;


cout << bst.sum(10, 40);
Test

 int values[] = { 32,19,23,33,76,1,37,53,18,89,28,1,77,52,


BinarySearchTree<int> bst;
for (int i = 0; i < 15; ++i) {
bst.add(values[i]);
}

cout << bst.find(34) << endl;


cout << bst.sum(10, 40);

 int values[] = { 25,29,57,30,62,56,60,55,88,56,70,83,56,7


BinarySearchTree<int> bst;
for (int i = 0; i < 15; ++i) {
bst.add(values[i]);
}

cout << bst.find(34) << endl;


cout << bst.sum(10, 40);

 int values[] = { 75,13,83,83,30,40,10,86,17,21,45,22,22,7


BinarySearchTree<int> bst;
for (int i = 0; i < 15; ++i) {
bst.add(values[i]);
}

cout << bst.find(34) << endl;


cout << bst.sum(10, 40);

Passed all tests! 

Đúng
Marks for this submission: 1,00/1,00. 
Câu hỏi 8
Đúng

Đạt điểm 1,00 trên 1,00

Given class BinarySearchTree, you need to finish method getMin() and getMa


#include <iostream>
#include <string>
#include <sstream>

using namespace std;

template<class T>
class BinarySearchTree
{
public:
class Node;

private:
Node* root;

public:
BinarySearchTree() : root(nullptr) {}
~BinarySearchTree()
{
// You have to delete all Nodes in BinaryTree. However in t
}

class Node
{
private:
T value;
Node* pLeft, * pRight;
friend class BinarySearchTree<T>;

public:
Node(T value) : value(value), pLeft(NULL), pRight(NULL) {}
~Node() {} 
};
Node* addRec(Node* root, T value);
void add(T value) ;
// STUDENT ANSWER BEGIN
// STUDENT ANSWER END
};

For example:

Test Result

BinarySearchTree<int> bst; 0
for (int i = 0; i < 10; ++i) { 9
bst.add(i);
}
cout << bst.getMin() << endl;
cout << bst.getMax() << endl;

Answer: (penalty regime: 5, 10, 15, ... %)

Reset answer

1 ▼ T getMin() {
2 if (root == nullptr) throw std::runtime_error("Binary
3 Node* currentNode = root;
4 ▼ while (currentNode->pLeft != nullptr) {
5 currentNode = currentNode->pLeft;
6 }
7 return currentNode->value;
8 }
9

10 ▼ T getMax() {
11 if (root == nullptr) throw std::runtime_error("Binary
12 Node* currentNode = root;
13 ▼ while (currentNode->pRight != nullptr) {
14 currentNode = currentNode->pRight;
15 }
15 }
16 return currentNode->value;
17 }
18

Test

 BinarySearchTree<int> bst;
for (int i = 0; i < 10; ++i) {
bst.add(i);
}
cout << bst.getMin() << endl;
cout << bst.getMax() << endl;

 int values[] = { 66,60,84,67,21,45,62,1,80,35 };


BinarySearchTree<int> bst;
for (int i = 0; i < 10; ++i) {
bst.add(values[i]);
}

cout << bst.getMin() << endl;


cout << bst.getMax() << endl;

 int values[] = { 38,0,98,38,99,67,19,70,55,6 };


BinarySearchTree<int> bst;
for (int i = 0; i < 10; ++i) {
bst.add(values[i]);
} 

cout << bst.getMin() << endl;


cout << bst.getMax() << endl;
Test

 int values[] = { 34,81,73,48,66,91,19,84,78,79 };


BinarySearchTree<int> bst;
for (int i = 0; i < 10; ++i) {
bst.add(values[i]);
}

cout << bst.getMin() << endl;


cout << bst.getMax() << endl;

 int values[] = { 94,61,75,36,34,58,62,74,54,90 };


BinarySearchTree<int> bst;
for (int i = 0; i < 10; ++i) {
bst.add(values[i]);
}

cout << bst.getMin() << endl;


cout << bst.getMax() << endl;

 int values[] = { 32,0,2,84,34,78,70,60,95,71,26,62,0,22,9


BinarySearchTree<int> bst;
for (int i = 0; i < 15; ++i) {
bst.add(values[i]);
}

cout << bst.getMin() << endl;


cout << bst.getMax() << endl;

 int values[] = { 53,24,32,40,80,47,81,88,42,29,31,91,77,7


BinarySearchTree<int> bst;
for (int i = 0; i < 15; ++i) {
bst.add(values[i]);
} 

cout << bst.getMin() << endl;


cout << bst.getMax() << endl;
Test

 int values[] = { 32,19,23,33,76,1,37,53,18,89,28,1,77,52,


BinarySearchTree<int> bst;
for (int i = 0; i < 15; ++i) {
bst.add(values[i]);
}

cout << bst.getMin() << endl;


cout << bst.getMax() << endl;

 int values[] = { 25,29,57,30,62,56,60,55,88,56,70,83,56,7


BinarySearchTree<int> bst;
for (int i = 0; i < 15; ++i) {
bst.add(values[i]);
}

cout << bst.getMin() << endl;


cout << bst.getMax() << endl;

 int values[] = { 75,13,83,83,30,40,10,86,17,21,45,22,22,7


BinarySearchTree<int> bst;
for (int i = 0; i < 15; ++i) {
bst.add(values[i]);
}

cout << bst.getMin() << endl;


cout << bst.getMax() << endl;

Passed all tests! 

Đúng
Marks for this submission: 1,00/1,00. 

You might also like