首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

有时候会出现处最可能的错误: 0x40010005: Control-C或者

2012-07-28 
有时候会出现处最可能的异常: 0x40010005: Control-C或者现在碰到一个问题,就是写了一个二叉查找树的程序,

有时候会出现处最可能的异常: 0x40010005: Control-C或者
现在碰到一个问题,就是写了一个二叉查找树的程序,只有插入和找successor的函数在,就想测试一下successor这个函数对不对,就调试了一下程序,用的是 visual studio 2010
有时候就能正常运行,
但是有时候就会跳出下面的这个几个错误中的一个
最可能的异常: 0x40010005: Control-C 或者
0x00000000 处最可能的异常: 0xC0000005: 读取位置 0x00000000 时发生访问冲突 

一般我停止调试后重新调试,就没有问题,但是有时候就又会出现,同样的一个程序没有做任何改动。现在不知道怎么办了。请大神们帮助。

运行的时候输入5 是正确运行的,但是当我想输入 其他的数据的时候就会调试中断报上面的错误。
有时候输入5也会中断报错。程序完全没有变动过,就是不停地调试停止再调试,就会出现不同的结果。。

代码如下:


#include <stdio.h>
#include <iostream>


using namespace std;

class bNode
{
public:

int key;
bNode* leftC;
bNode* rightC;

bNode* parent;//parent node pointer

bNode(int val):key(val),leftC(NULL),rightC(NULL),parent(NULL){};


};

class bTree
{
public:

bool insertNode(int val);

bNode* searchMin(bNode* x);

bNode* searchSuccessor(bNode* t);//find the successor--the min number which is bigger than this


bNode* searchNode(int key);//Check whether there exist such key number and return the pointer of that number ,if not exist return NULL


bNode* root;

bTree(void);
~bTree(void);


};

bNode* bTree::searchMin( bNode* x)
{
bNode* tem=x;
while (tem->leftC!=NULL)
{
tem=tem->leftC;
cout<<"node is :"<<tem->key<<endl;
}

return tem;
}

bool bTree::insertNode(int val)
{
bNode* x=root;
bNode* y=NULL;

while (x!=NULL)
{
y=x;
if (val<x->key)
{
x=x->leftC;
}
else if(val>x->key)
{
x=x->rightC;
}
else if(val==x->key)
{
cout<<"Data "<<val;
cout<<" already exist"<<endl<<endl<<endl<<endl;

return false;
}
}

if (y==NULL)
{
root=new bNode(val);
return true;

}
else if (val==y->key)
{
cout<<"Data "<<val;
cout<<" already exist"<<endl<<endl<<endl<<endl;

return false;
}
else if (val<y->key)
{
y->leftC= new bNode(val);
return true;
}
else
{
y->rightC=new bNode(val);
return true;
}

}

bTree::bTree(void)
{
root=NULL;
}
bTree::~bTree(void)
{

}

bNode* bTree::searchSuccessor(bNode* nod)
{
bNode*x =nod;
if (x->rightC!=NULL)
{
return searchMin(x->rightC);
}

bNode* y=x->parent;
while(y!=NULL && x==y->rightC)
{
x=y;
y=y->parent;
}

cout<<"successor is :"<<y->key<<endl;

return y;



}

bNode* bTree::searchNode(int key)
{
bNode* p=root;

if(key==p->key)
{
return p;
}
else if(key<p->key)
{
p=p->leftC;
}
else if (key>p->key)
{
p=p->rightC;
}
else
{
return NULL;
}
return NULL;
}

void main()
{
bTree binaryTree;

binaryTree.insertNode(5);
binaryTree.insertNode(3);
binaryTree.insertNode(8);
binaryTree.insertNode(2);
binaryTree.insertNode(4);
binaryTree.insertNode(1);
binaryTree.insertNode(7);
binaryTree.insertNode(12);
binaryTree.insertNode(13);
binaryTree.insertNode(10);


int k;
bNode* s1=NULL;
bNode* s2=NULL;

cout<<"Please enter the data you want to delete"<<endl;
cin>>k;


s1=binaryTree.searchNode(k);



cout<<"data is: "<<s1->key<<" it's address is"<< s1 <<endl<<endl<<endl<<endl<<endl;


s2=binaryTree.searchSuccessor(s1);
cout<<"successor is: "<<s2->key<<" it's address is"<< s2 <<endl<<endl<<endl<<endl<<endl;

system("pause");
}

[解决办法]
读取位置 0x00000000 时发生访问冲突

这说明你引用了个空指针了啊

热点排行