我在嘗試二叉樹的建立的時候出現:
// 引發了未經處理的例外:讀取訪問權限沖突。tree 是 0xFFFFFFF8。
// Run-Time Check Failure #2 - Stack around the variable 'tre)
等錯誤,網上查詢很多說的也是指標的問題,但是我還是找不到問題出處。請大佬們指教!

下面是我寫的
#include <stdio.h>
#include<stdlib.h>
//樹的結構
typedef struct ThreadNode{
char data;
int ltag, rtag; // tag等于1時表明是線索
struct ThreadNode* lchild, * rchild;
}ThreadNode, *ThreadTree;
//線索
void initTag(ThreadNode* node)
{
node->ltag = node->rtag = 0;
}
ThreadNode* pre = NULL;
//線索二叉樹的建立
ThreadTree creatTree()
{
ThreadTree tree;
char str;
str = getchar();
if (str == '#')
tree = NULL;
else {
tree = (ThreadNode*)malloc(sizeof(ThreadNode));
initTag(&tree);
tree->data = str;
tree->lchild = creatTree();
tree->rchild = creatTree();
}
return tree;
}
/// 中序遍歷線索二叉樹
void visit(ThreadNode* node)
{
if ((*node).lchild == NULL)
{
(*node).lchild = pre;
(*node).ltag = 1;
}
if (pre != NULL && pre->rchild == NULL)
{
pre->rchild = node;
pre->rtag = 1;
}
pre = node;
}
int main()
{
ThreadTree tree = creatTree();
InThread(&tree);
return 0;
}
輸入:ABC##D###
uj5u.com熱心網友回復:
懂了是我在對樹結點的線索進行初始化的時候,傳的是一個一級指標的地址,而函式的接收同樣是一個一級指標導致出錯!轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/259585.html
標籤:C語言
上一篇:結構體里的動態陣列輸入問題
下一篇:OpenGL大佬請看一眼
