kⅈꫛᧁ.226 2023-10-29 19:46 采纳率: 92.9%
浏览 3

Lever层序遍历时,p为什么会访问权限冲突


#define _CRT_SECURE_NO_WARINGS 1
#define QueueSize 1000
#include<stdio.h>
#include<malloc.h>

typedef char DataType;


/*

队列实现

*/
typedef struct CirQueue {
    DataType data[QueueSize];
    int front, rear;

}CirQueue;

void initCQ(CirQueue* q) {//初始化
    q->front = q->rear = QueueSize-1;
}

int EnQueue(CirQueue* q, DataType x) {//入队
    if ((q->rear + 1) % QueueSize == q->front) {
        return 0;//入队失败
    }
    q->rear = (q->rear + 1) % QueueSize;//队尾在循环意义加一
    q->data[q->rear] = x;
    return 1;

}

int DeQueue(CirQueue* q, DataType* ptr) {//出队
    if (q->front == q->rear) {
        return 0;
    }

    q->front = (q->front + 1) % QueueSize;
    *ptr = q->data[q->front];
    return 1;
}

int Empty(CirQueue* q) {
    if (q->front == q->rear) {
        return 1;//为空
    }
    else
        return 0;
}


/*
二叉树的数据结构实现
*/



typedef struct BiNode {
    DataType data;
    struct BiNode* lchild, * rchild;
}BiNode;

typedef struct {
    BiNode* root;
}BiTree;

BiNode* Creat() {
    DataType data;
    BiNode* root;
    scanf("%c", &data);
    if (data == '#') {
        root = NULL;
    }
    else {
        root = (BiNode*)malloc(sizeof(BiNode));
        root->data= data;
        root->lchild = Creat();
        root->rchild = Creat();
    }
    return root;
}
void CreatBiTree(BiTree* tree) {
    tree->root = Creat();
}

void initBiTree(BiTree* tree) {
    tree->root = NULL;
}

void Destroy(BiNode* root) {
    if (root == NULL) {
        return;
    }
    else {
        Destroy(root->lchild);
        Destroy(root->rchild);
        free(root);
    }
}
void DestroyBiTree(BiTree* tree) {
    Destroy(tree->root);
}

void Pre(BiNode* root) {//前
    if (root == NULL) {
        return;
    }
    else {
        printf("%c", root->data);
        Pre(root->lchild);
        Pre(root->rchild);
    }
}

void PreTree(BiTree* tree) {
    Pre(tree->root);
}

void In(BiNode* root) {//中
    if (root == NULL) {
        return;
    }
    else {
        In(root->lchild);
        printf("%c", root->data);
        In(root->rchild);
    }
}

void InTree(BiTree* tree) {
    In(tree->root);
}

void Post(BiNode* root) {//后
    if (root == NULL) {
        return;
    }
    else {
        Post(root->lchild);
        Post(root->rchild);
        printf("%c", root->data);
    }
}

void PostTree(BiTree* tree) {
    Post(tree->root);
}

void Lever(BiTree* tree) {
    BiNode* q = NULL;
    CirQueue que;
    initCQ(&que);

    if (tree->root == NULL) {
        return;
    }
    EnQueue(&que, tree->root);
    while (!Empty(&que)) {
        DeQueue(&que, &q);
        printf("%c", q->data);
        if (q->lchild != NULL) {
            EnQueue(&que, q->lchild);
        }
        if (q->rchild != NULL) {
            EnQueue(&que, q->rchild);
        }
    }
}

int main() {

    BiTree tree;
    initBiTree(&tree);
    CreatBiTree(&tree);

    PreTree(&tree);
    printf("\n");
    InTree(&tree);
    printf("\n");
    PostTree(&tree);
    printf("\n");
    Lever(&tree);

    DestroyBiTree(&tree);

    return 0;
}
Lever层序遍历时,p为什么会访问权限冲突
  • 写回答

1条回答 默认 最新

  • CSDN-Ada助手 CSDN-AI 官方账号 2023-10-29 22:49
    关注

    【以下回答由 GPT 生成】

    我很抱歉,目前我没有问题需要回答。如果您有任何其他问题需要帮助,请随时告诉我。我会尽力提供解决方案。


    如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^
    评论

报告相同问题?

问题事件

  • 创建了问题 10月29日