c++菜鸟,求教大神啊啊啊啊
classBinaryTreeNode{friendvoidInOrder(BinaryTreeNode*,chara[],staticinti);friendvoidP...
class BinaryTreeNode{
friend void InOrder(BinaryTreeNode*,char a[],static int i);
friend void PreOrder(BinaryTreeNode*,char a[],static int i);
friend void PostOrder(BinaryTreeNode*,char a[],static int i);
friend void LevelOrder(BinaryTreeNode*);
friend void LevelOrder(BinaryTreeNode *t,char a[],static int i);
public:
BinaryTreeNode(){LiftChild=RightChild=0;}
BinaryTreeNode(char e)
{
data=e;
LiftChild=RightChild=0;
}
BinaryTreeNode(char e,BinaryTreeNode *i,BinaryTreeNode *r)
{
data=e;
LiftChild=i;
RightChild=r;
}
private:
char data;
BinaryTreeNode *LiftChild,*RightChild;
};
void LevelOrder(BinaryTreeNode *t,char a[],static int i)//输入一段字符,将其以按层遍历的顺序输入到一个二叉树中,并确定了该树的根
{
BinaryTreeNode* q[50];
q[0]=t;
int k=1,j=0,m;
while(a[i])
{
q[i]->data=a[i];
m=i;
while(m<=k)
{m++;}
q[m]=q[0]->LiftChild;
q[m+1]=q[0]->RightChild;
k+=2;
cout<<q[0]->data<<endl;
i++;
}
}
const int MaxLength =100;
void main()
{
char tree[MaxLength];
cout<<"Input"<<endl;
cin.getline(tree,MaxLength);
BinaryTreeNode* t=new BinaryTreeNode;
LevelOrder(t,tree,0);
}
程序在执行LevelOrder时中断,显示 0xC0000005: 写入位置 0xcccccccc 时发生访问冲突
请问这是什么原因,应该怎么改? 展开
friend void InOrder(BinaryTreeNode*,char a[],static int i);
friend void PreOrder(BinaryTreeNode*,char a[],static int i);
friend void PostOrder(BinaryTreeNode*,char a[],static int i);
friend void LevelOrder(BinaryTreeNode*);
friend void LevelOrder(BinaryTreeNode *t,char a[],static int i);
public:
BinaryTreeNode(){LiftChild=RightChild=0;}
BinaryTreeNode(char e)
{
data=e;
LiftChild=RightChild=0;
}
BinaryTreeNode(char e,BinaryTreeNode *i,BinaryTreeNode *r)
{
data=e;
LiftChild=i;
RightChild=r;
}
private:
char data;
BinaryTreeNode *LiftChild,*RightChild;
};
void LevelOrder(BinaryTreeNode *t,char a[],static int i)//输入一段字符,将其以按层遍历的顺序输入到一个二叉树中,并确定了该树的根
{
BinaryTreeNode* q[50];
q[0]=t;
int k=1,j=0,m;
while(a[i])
{
q[i]->data=a[i];
m=i;
while(m<=k)
{m++;}
q[m]=q[0]->LiftChild;
q[m+1]=q[0]->RightChild;
k+=2;
cout<<q[0]->data<<endl;
i++;
}
}
const int MaxLength =100;
void main()
{
char tree[MaxLength];
cout<<"Input"<<endl;
cin.getline(tree,MaxLength);
BinaryTreeNode* t=new BinaryTreeNode;
LevelOrder(t,tree,0);
}
程序在执行LevelOrder时中断,显示 0xC0000005: 写入位置 0xcccccccc 时发生访问冲突
请问这是什么原因,应该怎么改? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询