using namespace std;
typedef struct {
void *items[MAX];
int front;
int rear;
} Queue;
void InitQueue(Queue *q) {
q->front = -1;
q->rear = -1;
}
int IsEmpty(Queue *q) {
return q->front == -1;
}
int IsFull(Queue *q) {
return q->rear == MAX - 1;
}
void enqueue(Queue *q, void *value) {
if (IsFull(q)) {
printf("Queue is full\n");
return;
}
if (IsEmpty(q)) {
q->front = 0;
}
q->items[++q->rear] = value;
}
void *dequeue(Queue *q) {
if (IsEmpty(q)) {
printf("Queue is empty\n");
return NULL;
}
void *item = q->items[q->front++];
if (q->front > q->rear) {
q->front = q->rear = -1;
}
return item;
}
typedef struct node
{
char data;
struct node * lchild;
struct node * rchild;
}BiTree;
BiTree* newNode(char v) {
BiTree*Node =(BiTree*)malloc(sizeof(BiTree));
Node->data = v;
Node->lchild = Node->rchild = NULL;
return Node;
}
BiTree* insert(BiTree *root, int x) {
if (root == NULL) {
root = newNode(x);
return root;
}
else if (root->data > x) {
root->lchild=insert(root->lchild, x);
}
else {
root->rchild=insert(root->rchild, x);
}
return root;
}
void visit(BiTree *root){
printf("%c",root->data);
}
void PreOrder(BiTree *root){
if(root!=NULL) {
visit(root);
PreOrder(root->lchild);
PreOrder(root->rchild);
}
}
void InOrder(BiTree *root){
if(root!=NULL){
InOrder(root->lchild);
visit(root);
InOrder(root->rchild);
}
}
void PostOrder(BiTree *root){
if(root!=NULL){
PostOrder(root->lchild);
PostOrder(root->rchild);
visit(root);
}
}
void LevelOrder(BiTree *root) {
if (root == NULL) {
printf("Tree is empty\n");
return;
}
Queue q;
InitQueue(&q);
enqueue(&q, root);
while (!IsEmpty(&q)) {
BiTree *root = (BiTree *)dequeue(&q);
visit(root);
if (root->lchild != NULL) {
enqueue(&q, root->lchild);
}
if (root->rchild != NULL) {
enqueue(&q, root->rchild);
}
}
}
int wplPreOrder(BiTree *root,int deep){
static int wpl=0;
if(root->lchild==NULL && root->rchild==NULL){
wpl+=(root->data)*deep;
}
if(root->lchild!=NULL){
wplPreOrder(root->lchild,deep+1);
}
if(root->rchild!=NULL){
wplPreOrder(root->rchild,deep+1);
}
return wpl;
}
void express(BiTree *root,int deep){
if(root!=NULL){
if(root->lchild==NULL && root->rchild==NULL){
printf("%c",root->data);
}
else{
if(deep>0){
printf("(");
}
express(root->lchild,deep+1);
visit(root);
express(root->rchild,deep+1);
if(deep>0){
printf(")");
}
}
}
}
typedef struct {
int SqBitnode[MAX];
int num;
}Sqbitree;
void increase(Sqbitree &t){
t.SqBitnode[0]=
}
int main() {
Sqbitree &t;
BiTree *root=NULL;
root=newNode('*');
BiTree *s1=newNode('+');
BiTree *s2=newNode('*');
BiTree *s3=newNode('a');
BiTree *s4=newNode('b');
BiTree *s5=newNode('c');
BiTree *s6=newNode('-');
BiTree *s7=newNode('d');
root->lchild=s1;
root->rchild=s2;
s1->lchild=s3;
s1->rchild=s4;
s2->lchild=s5;
s2->rchild=s6;
s6->rchild=s7;
return 0;
}