classMyCircularQueue{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 circular queue. Return true if the operation is successful. */boolenQueue(int value){if(size == capacity){returnfalse;}array[rear]= value;rear =(rear +1)% capacity;size++;returntrue;}/** Delete an element from the circular queue. Return true if the operation is successful. */booldeQueue(){if(size ==0){returnfalse;}front =(front +1)% capacity;size--;returntrue;}/** Get the front item from the queue. */intFront(){if(size ==0){return-1;}return array[front];}/** Get the last item from the queue. */intRear(){if(size ==0){return-1;}return array[(rear + capacity -1)% capacity];}/** Checks whether the circular queue is empty or not. */boolisEmpty(){return size ==0;}/** Checks whether the circular queue is full or not. */boolisFull(){return size == capacity;}int*array;int capacity;int size;int front;int rear;};
前序遍历 /*** 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…