Assignment 2 - CSD201
Assignment 2 - CSD201
Input:
50 5 61 43 43 35 47 3 1 25
Tree
The class Car with 2 data members: owner and price is given and you do not need to
edit it. The BSTree class is a binary search tree of the Car object. The variable price
is the key of the tree. The following methods should be completed:
void f0_getInformation(){
● void insert(string xOwner, int xPrice) - check if the second character of xOwner
equals 'X' or xPrice >100 then do nothing, otherwise insert a new car with
owner=xOwner, price=xPrice to the tree.
● void f1() – You do not need to edit this function. Your task is to complete the
insert(...) function above only.
[email protected] 1
Your selection (1 -> 10): 1
Input :(AB,50) (BA,5) (BD,61) (A2,3) (EB,43) (A1,1) (G1,35) (X2,47) (B2,25)
● void f2() – Perform in-order traversal from the root but only displays nodes with
prices in the range [3,50]..
Input :(A1,1) (A2,3) (BA,5) (B2,25) (G1,35) (EB,43) (X2,47) (AB,50) (BD,61)
● void f3() – Perform postOrder traversal from the root and delete by copying the first
node that has 2 children and its price between [30,70]
Input :(A1,1) (A2,3) (B2,25) (G1,35) (X2,47) (EB,43) (BA,5) (BD,61) (AB,50)
● void f4() – Perform inOrder traversal from the root and delete by Merging the first
node having left child and its price in the range [30,70].
Input :(A1,1) (A2,3) (BA,5) (B2,25) (G1,35) (EB,43) (X2,47) (AB,50) (BD,61)
● void f5() – Suppose p is 4-th node when perform pre_Order traversal from the root
of the tree and delete by Copy node p.
[email protected] 2
Input :(AB,50) (BA,5) (A2,3) (A1,1) (EB,43) (G1,35) (B2,25) (X2,47) (BD,61)
● void f6() – Suppose p is the 2-th node which has left node when performing
Bread_first traversal from the root of the tree then deletes by Merging node p.
Input :(AB,50) (BA,5) (BD,61) (A2,3) (EB,43) (A1,1) (G1,35) (X2,47) (B2,25)
● void f7() – Perform preOrder traversal from the root and find the first node p having
right child and its price in the range [30,70]. Rotate p to left about its right child.
Input :( AB,50) (BA,5) (A2,3) (A1,1) (EB,43) (G1,35) (B2,25) (X2,47) (BD,61)
● void f8() – Perform preOrder traversal from the root and find the first node p having
left child and its price in the range [30,70]. Rotate p to right about its left child.
Input :(AB,50) (BA,5) (A2,3) (A1,1) (EB,43) (G1,35) (B2,25) (X2,47) (BD,61)
● void f9(): Suppose p is the 7-th node when performing the in-order traversal of the
tree. Calculate the height p then assign that value to the heightofNode variable;
[email protected] 3
Your selection (1 -> 10): 9
Input :(A1,1) (A2,3) (BA,5) (B2,25) (G1,35) (EB,43) (X2,47) (AB,50) (BD,61)
Output: 1
void f10() Suppose p is the 5th node when performing the in-order traversal of the
tree, count the number of nodes in the subtree with root is Node p then assign that
value to the numberofNode variable;
Input :(A1,1) (A2,3) (BA,5) (B2,25) (G1,35) (EB,43) (X2,47) (AB,50) (BD,61)
Output: 2
Input :(AB,50) (BA,5) (BD,61) (A2,3) (EB,43) (A1,1) (G1,35) (X2,47) (B2,25)
output:5
Input :(AB,50) (BA,5) (BD,61) (A2,3) (EB,43) (A1,1) (G1,35) (X2,47) (B2,25)
output:4
int f13() count and return all Node have both 2 children
Input :(AB,50) (BA,5) (BD,61) (A2,3) (EB,43) (A1,1) (G1,35) (X2,47) (B2,25)
output:3