- #1
diredragon
- 323
- 15
Homework Statement
Write a BinaryTree Class using these specifications:
A Class Node represents a standard node of the tree with fields and a constructor like given below:
Code:
int start, end;
const Complex* value; //I will provide more information about Complex later because that was the part of another assignment had and is used here also.
Node *left;
Node *right;
public:
Node(int start, int end, const Complex* val);
Code:
Node::Node(int startt, int endd, const Complex* val) {
start = startt;
end = endd;
value = val; //btw is this ok? Can i lose this val when i leave the function so i would need to do something else here?
left = nullptr;
right = nullptr;
}
Code:
Node* root;
BinaryTree(vector<Complex*>& numbers);
A Binary Tree is created from an array of Complex numbers in this manner:
The ROOT has the indexes as the array meaning start equals beginning of array and end equals end of array and the value of the sum of all the numbers in the array. The Node to the LEFT of the ROOT has the indexes from the start to the middle of the array (including middle if odd number of values in array) and the value of the sum of Complex those indexes include. The Node to the RIGHT has the remaining in the same manner. This continues until there are all the values of the array in the tree's leaves, meaning those leaves have the indexes of only one number in the array.
Homework Equations
3. The Attempt at a Solution [/B]
A Little something about Complex which is mentioned here:
Complex is a Class which represents Complex numbers. It has two fields: The REAL part and the IMAGINARY part. You can create a Complex number like this:
Code:
Complex number1("23 + 12i");
Code:
Complex number3(number1 + number2);
Code:
class BinaryTree {
Node *root;
public:
BinaryTree(vector<Complex*>& numbers);
};
BinaryTree::BinaryTree(vector<Complex*>& numbers) {
//...
}