Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8730817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:06:08+00:00 2026-06-13T09:06:08+00:00

I have written a code for avl which is giving me the below error

  • 0

I have written a code for avl which is giving me the below error after executing/mid way during execution.
I guess its some kind of memory leak issue. Can somebody point out what should be fixed ?
Codeblocks gave a popup segmentation error.
Error : Unhandled exception at 0x77B2A710 (ntdll.dll) in ADS Project.exe: 0xC0000005: Access violation writing location 0x00000014.

Code:

{
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;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:06:09+00:00Added an answer on June 13, 2026 at 9:06 am

    One issue I could see is:

    AVL *avlTree = (AVL *) malloc(1000000* sizeof(AVL *));
    

    should be

    AVL *avlTree = (AVL *) malloc(1000000* sizeof(AVL));
                                                  ^^^
    

    There might be more. A debugger is your best friend in situations like this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written code for threading in Python. It throws the error below. How
I have written some code in JSP to download .docx files which is hosted
I have written code such as the following, which by assumption shouldn't compile. I'm
I have a image for which i have written code in MouseMove to higlight
I have written code in C# which is exceeding page width, so I want
Below i have written code of a soap webservice in php with its client,It
I have written code which saves a user's answers as well as a recorded
I have written code below.but it will print this exception and i really don't
I have written code within Python that doesn't release memory the way it should.
I have written code which performs a specific task; now when I will run

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.