실행 중/중간 방법을 수행 한 후 아래 오류가 발생하는 avl 코드를 작성했습니다.
메모리 누수 문제가 발생합니다. 누군가가 고쳐야 할 것을 지적 할 수 있습니까? Codeblocks에서 팝업 세분화 오류가 발생했습니다. 오류 : Unhandled exception at 0x77B2A710 (ntdll.dll) in ADS Project.exe: 0xC0000005: Access violation writing location 0x00000014.
AVL 트리에 대한 C++ 코드에서 액세스 위반 오류가 발생합니다.
코드 :
{
InputGenerator ip;
int numbers[1000000];
ip.RandomInput(numbers, 1000000);
AVL *avlTree = (AVL *) malloc(1000000* sizeof(AVL *));
AVL *root = NULL;
auto avlOps = make_shared <AVL>();
int input = 0;
*avlTree = AVL(numbers[0]);
root = avlTree;
avlTree++;
int balanceFac = 0;
input = 1;
while (input != 1000000)
{
//cout << "sorting : ";
//avlOps->InorderPrint(root);
cout << endl;
cout << "Inserting : " << numbers[input] << endl;
*avlTree = AVL(numbers[input]);
avlOps->Insert(avlTree, root);
// check if rotation is required.
AVL * tempNo=avlTree->GetParent();
while(tempNo!=NULL)
{
int balFac=0;
AVL* node1=NULL;
AVL* node2=NULL;
AVL* node3=NULL;
int rCase=0;
balFac=avlOps->GetBalanceFactor(tempNo);
if(balFac>1||balFac<-1)
{
node1=tempNo;
if(balFac>0)
{
node2=node1->GetLChild();
balFac=avlOps->GetBalanceFactor(node2);
if(balFac>0)
{
node3=node2->GetLChild();
rCase=1;
}
else
{
node3=node2->GetRChild();
rCase=3;
}
}
else
{
node2=node1->GetRChild();
balFac=avlOps->GetBalanceFactor(node2);
if(balFac>0)
{
node3=node2->GetLChild();
rCase=4;
}
else
{
node3=node2->GetRChild();
rCase=2;
}
}
root=avlOps->Rotation(node1,node2,node3,root,rCase);
}
tempNo=tempNo->GetParent();
}
cout<<endl;
cout << "Root :" << root->GetKey() << endl;
cout << "******" << endl;
avlTree++;
input++;
}
avlOps->InorderPrint(root);
return 0;
}
디버거를 사용해 보셨습니까? – jogojapan
그냥 나를 chkstk.asm에 이르게한다. 나는 C++을 처음 사용하기 때문에 파일의 많은 부분을 만들 수 없다. 그리고 코드에 실제로 들어갈 수 없다. – Shekhar
그래서 디버거를 사용하고 있는가? 이 경우 오류가 발생하면 호출 스택의 내용을 출력하게하십시오. 즉각적인 오류를 일으킨 코드 줄을 알려줍니다. (실제 문제는 어딘가에 있을지 모르지만 여전히 잘못된 점을 발견하는 데 도움이됩니다.) – jogojapan