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 8916041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:07:58+00:00 2026-06-15T05:07:58+00:00

I have an assignment to create a PriorityQueue structure and I’m having trouble with

  • 0

I have an assignment to create a PriorityQueue structure and I’m having trouble with this piece of code. When I compile it on my compilator everything’s fine, but I tried submitting it to ideone and I get the following error:

“glibc detected *** ./prog: double free or corruption”.

I was able to track the part that was giving me this error and I found out that what causes the crash is me trying to delete a pointer at the destructor of my class. The problem is that I don’t know why I cant delete it. I don’t know a lot about pointers but I thought that if I used new to allocate memory I had to delete it after using it and I think this is what I’m trying to do. Here is my code:

struct PriorityQueue
{
LinkedList queue; LinkNode *it,*node;
int sz;

PriorityQueue(){
    sz=0;
    queue.head=NULL;
    queue.tail=NULL;
    it = NULL;
    node=NULL;
}

~PriorityQueue(){

    if(node != NULL) //this is causing the error.
    delete [] node;


    if(it != NULL)
    delete [] it;
}


int size(){

    return sz;
}


void enqueue(int x){

    node = new LinkNode(x,NULL,NULL);

    if(sz==0){

        queue.insert_head(x);
        sz++;

    }

    else{

    if(x <= queue.head->value ){

        queue.insert_head(x);
        sz++;

    }

    else if( x>= queue.tail->value ){

        queue.insert_tail(x);
        sz++;

    }
    else{

        it = queue.head;


        for(int k=0;k<sz;k++){

                if( (x>= it->value)  && (x <= it->next->value) ){

                     node->next= it->next;
                     node->previous = it;

                     it->next->previous = node;
                     it->next = node;
                     sz++;
                     break;

                }

                    it=it->next;

        }

    }


    }

}

int dequeue_min(){

    int min = queue.remove_head();
    sz--;


    return min;
}

int dequeue_max(){

    int max= queue.remove_tail();
    sz--;

    return max;
}


};



int main()
{
PriorityQueue pq;
pq.enqueue(4);
pq.enqueue(2);
pq.enqueue(7);
pq.enqueue(-6);
pq.enqueue(0);
cout << pq.dequeue_min() << endl;   // debe imprimir -6
cout << pq.dequeue_min() << endl;   // debe imprimir 0
pq.enqueue(3);
cout << pq.dequeue_min() << endl;   // debe imprimir 2
cout << pq.dequeue_min() << endl;   // debe imprimir 3

return 0;
}

Thanks.

  • 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-15T05:08:00+00:00Added an answer on June 15, 2026 at 5:08 am

    it and node point to objects, not arrays.
    You cannot use the array form of delete[] on them.

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

Sidebar

Related Questions

I have an assignment to create a GUI using MATLAB GUIDE and am having
This is a practice assignment where I have to create a table space with
I have an assignment to create a print view using HTML & CSS. This
I have an assignment to create a secure communication between 2 people with a
For a school assignment I have to create a C++ program that will create
I have a small assignment in C. I am trying to create an array
For my second programming assignment in my Java class, we have to create a
I have an assignment to learn how to use boost::variant. I'm trying to create
I have a database assignment which I have to create some relational algebra for
I currently have an assignment to create a filesystem in Java. I am trying

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.