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

(递归建立二叉搜索树时异常)Unhandle exception in FaceR.exe(NTDLL.DLL):0XC0000005:Access Viola

2012-03-30 
(递归建立二叉搜索树时错误)Unhandle exception in FaceR.exe(NTDLL.DLL):0XC0000005:Access Violationvoi

(递归建立二叉搜索树时错误)Unhandle exception in FaceR.exe(NTDLL.DLL):0XC0000005:Access Violation
void BSTree::CreateBSTree(BSTree *&BST,vector<t_point> databag,unsigned int n)
{

BST->data=databag;
BST->left=BST->right=NULL;
vector<t_point> leftnode;
  vector<t_point> rightnode; //t_point是我自己定义的一个类,该类里面包含一个一维的数组
static int dep=0;
int k=dep%3;
  double midd=mid(databag,databag.size(),k); //求取最中间大小的值
BST->discr=midd;
for(unsigned int i=0;i<(databag.size());i++) //根据是否大于中间值的大小来建立leftnode和rightnode
{
if(databag[i].dot[k]>=midd)
{
t_point *pi=new t_point(databag[i].dot[0],databag[i].dot[1],databag[i].dot[2]);
rightnode.push_back(*pi);
}
else
{
t_point *pi=new t_point(databag[i].dot[0],databag[i].dot[1],databag[i].dot[2]);
leftnode.push_back(*pi);
}

dep++;
if(databag.size()>10) //我把这修改成1000就正常了。但是我需要它小于20
{
if(rightnode.size()!=0)
{
BST->right=new BSTree;  
CreateBSTree(BST->right,rightnode,unsigned int(rightnode.size())); //创建左子数}
if(leftnode.size()!=0)
{
BST->left=new BSTree;
CreateBSTree(BST->left,leftnode,unsigned int(leftnode.size())); //创建左子数}
}
}

处理的数据有6000个左右。

[解决办法]
帮顶~

热点排行