再写循环队列 class MyCircularQueue {
public:/** Initialize your data structure here. Set the size of the queue to be k. */MyCircularQueue(int k) {array (int *)malloc(sizeof(int)*k);capacity k;size 0;front 0;rear 0;}/** Insert an element into the circu…
前序遍历 /*** Definition for a binary tree node.* struct TreeNode {* int val;* struct TreeNode *left;* struct TreeNode *right;* };*//*** Note: The returned array must be malloced, assume caller calls free().*/
int *array;
int size;void _preorde…
平衡二叉树 /*** Definition for a binary tree node.* struct TreeNode {* int val;* struct TreeNode *left;* struct TreeNode *right;* };*/int MAX(int a,int b)
{return a > b ? a : b;
}//求高度
int getHeight(struct TreeNode *root){if(root NULL){…
前序中序遍历构造二叉树 思路
在前序中找根结点根据根结点 中序,分成左右两棵子树根据子树长度,把前序分成左右两颗子树递归处理子树
/*** Definition for a binary tree node.* struct TreeNode {* int val;* struct TreeNode *left;* s…