计算二叉树的高c++源代码
时间: 2023-12-20 08:06:15 浏览: 129
二叉树c++代码
dst2->width = src->width;
dst2->height = src->height;
dst2->channels = src->channels;
dst2->data = new Pixel[src->width * src->height];
rotateImage(src, dst2, cx, cy, angle下面是计算二叉树高度的 C++ 代码:
```c++
#include <iostream>
using namespace std;
struct TreeNode);
saveImage("output_2.bmp", dst2);
releaseImage(dst2);
// 缩放变换
Image *dst3 = new Image;
dst3->width = (int)(src->width * scale_x + 0.5);
dst {
int val;
TreeNode* left;
TreeNode* right;
TreeNode(int x): val(x), left(nullptr), right(nullptr)3->height = (int)(src->height * scale_y + 0.5);
dst3->channels = src->channels;
{}
};
int getTreeHeight(TreeNode* root) {
if(root == nullptr) {
return 0;
}
int leftHeight dst3->data = new Pixel[dst3->width * dst3->height];
scaleImage(src, dst3, scale_x, scale_y);
saveImage("output_3.bmp", dst3);
releaseImage(dst3);
// 剪切变换
= getTreeHeight(root->left);
int rightHeight = getTreeHeight(root->right);
return max(leftHeight, rightHeight) Image *dst4 = new Image;
dst4->width = src->width;
dst4->height = src->height;
dst4->channels = src->channels;
dst4->data = new Pixel[src->width * src->height];
shearImage + 1;
}
int main() {
// 构建一棵二叉树
TreeNode* root = new TreeNode(1);
(src, dst4, hx, hy);
saveImage("output_4.bmp", dst4);
releaseImage(dst4);
// root->left = new TreeNode(2);
root->right = new TreeNode(3);
root->left->left = new TreeNode 释放内存
releaseImage(src);
return 0;
}
```
注意:程序中的输入图像为 "input.bmp",需根据实际情况进行修改。
阅读全文