各路大哥麻烦看看在vs2019不能运行,在菜鸟在线编译可以运行
程序代码:
#include<stdio.h> #include<malloc.h> /* * 二叉树的遍历 */ typedef struct BTNode { char data;//数据域 struct BTNode* lchild;//左孩子指针域 struct BTNode* rchild;//右孩子指针域 }BTNODE, * PBTNODE; PBTNODE CreateBTree(void);//创建二叉树 void PreOrderTraverseBTree(PBTNODE pT);//二叉树先序遍历的递归算法 void InOrderTraverseBTree(PBTNODE pT);//中序 void PostOrderTraverseBTree(PBTNODE pT);//后序 int main(void) { PBTNODE pT = CreateBTree();//相当于 struct BTNode *pT=CreateBTree() //CreateBTree函数返回的是指向树根的指针 printf("前序遍历 \n"); PreOrderTraverseBTree(pT); printf("中序遍历 \n"); InOrderTraverseBTree(pT); printf("后序遍历 \n"); PostOrderTraverseBTree(pT); } PBTNODE CreateBTree(void) { PBTNODE pA = (PBTNODE)malloc(sizeof(BTNODE)); PBTNODE pB = (PBTNODE)malloc(sizeof(BTNODE)); PBTNODE pC = (PBTNODE)malloc(sizeof(BTNODE)); PBTNODE pD = (PBTNODE)malloc(sizeof(BTNODE)); PBTNODE pE = (PBTNODE)malloc(sizeof(BTNODE)); pA->data = 'A'; pB->data = 'B'; pC->data = 'C'; pD->data = 'D'; pE->data = 'E'; pA->lchild = pB; pA->rchild = pD; pB->lchild = NULL; pB->rchild = pC; pC->lchild = pC->rchild = NULL; pD->lchild = pE; pD->rchild = NULL; return pA; } void PreOrderTraverseBTree(PBTNODE pT) { if (pT != NULL) { printf("%c\n", pT->data); if (pT->lchild != NULL) { PreOrderTraverseBTree(pT->lchild); } if (pT->rchild != NULL) { PreOrderTraverseBTree(pT->rchild); } } } void InOrderTraverseBTree(PBTNODE pT) { if (pT != NULL) { if (pT->lchild != NULL) { InOrderTraverseBTree(pT->lchild); } printf("%c\n", pT->data); if (pT->rchild != NULL) { InOrderTraverseBTree(pT->rchild); } } } void PostOrderTraverseBTree(PBTNODE pT) { if (pT != NULL) { if (pT->lchild != NULL) { PostOrderTraverseBTree(pT->lchild); } if (pT->rchild != NULL) { PostOrderTraverseBTree(pT->rchild); } printf("%c\n", pT->data); } }
void PreOrderTraverseBTree(PBTNODE pT) {
if (pT != NULL) {
printf("%c\n", pT->data); 引发了异常: 读取访问权限冲突。 pT 是 0xCDCDCDCD。
if (pT->lchild != NULL) {
PreOrderTraverseBTree(pT->lchild);
}
if (pT->rchild != NULL) {
PreOrderTraverseBTree(pT->rchild);
}
}
}
if (pT != NULL) {
printf("%c\n", pT->data); 引发了异常: 读取访问权限冲突。 pT 是 0xCDCDCDCD。
if (pT->lchild != NULL) {
PreOrderTraverseBTree(pT->lchild);
}
if (pT->rchild != NULL) {
PreOrderTraverseBTree(pT->rchild);
}
}
}
而菜鸟在线编译时正常的