Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Tree::func() {
- const size_t nFloors = height() + 1;
- std::pair<int, int>* array = new std::pair<int, int>[nFloors];
- for (size_t i = 0; i < nFloors; i++) array[i].first = array[i].second = 0;
- size_t id = 0;
- nNodes(head, array, id);
- for (size_t i = 0; i < nFloors; i++) {
- std::cout << "Floor = " << i + 1 << " | nNodes = " << array[i].second
- << " | nLeafs = " << array[i].first << std::endl;
- }
- }
- void Tree::nNodes(Node* node, std::pair<int, int>*& array, size_t& floor_id) {
- if (node == nullptr) return;
- if (node->left == nullptr && node->right == nullptr)
- array[floor_id].first++;
- else {
- array[floor_id].second++;
- floor_id++;
- nNodes(node->left, array, floor_id);
- nNodes(node->right, array, floor_id);
- floor_id--;
- }
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement