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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:58:44+00:00 2026-06-13T17:58:44+00:00

I’m trying to create a two sided queue with c++. I’m using Visual Studio

  • 0

I’m trying to create a two sided queue with c++.
I’m using Visual Studio 2012 and keep getting:

First-chance exception at 0x00D95A29 in Console_Assignment1.exe: 0xC0000005: Access violation writing location 0x00000008.

I think i’m having a pointer issue (might be trying to dereference something i shouldn’t).
so far i have had zero luck finding the problem and i’d really appreciate a second look.

(The code is too long to paste so i’ll just copy the functions i think are giving me the problem.)
Maybe just a small overview. I have a node class that holds two pointer to node (next and previous) and an int (value). and a queue class that holds two pointers to node (first and last) and an int (size).

// enqueueBeg - adds a new node at the beginning of the queue.
void DBL_Queue::enqueueBeg(int insert_val)
{
node* new_node = new node(insert_val);  // Creates the new node.
new_node->setNext( this->getFirst() ); // Connects the new node to the first in the queue
this->getFirst()->setPrev( new_node ); // Connects the first node in the queue to the new one
this->setFirst( new_node );             // Sets the new node as the first in the queue
this->setSize ( this->get_queue_size() + 1 ); // adds 1 to the size of the list

// dequeueBeg - removes the first node of the queue.
int DBL_Queue::dequeueBeg()
{
int ret_value = this->getFirst()->getVal();
node* old_node = this->getFirst();
this->setFirst( this->getFirst()->getNext() ); // Sets the second node in the queue as the first.
this->getFirst()->setPrev( NULL ); // Removes the link between the new first new and the old one.
this->setSize( this->get_queue_size() - 1); // Removes 1 from queue size
delete old_node;  // Deletes the node that use to be first.
return ret_value; // Returns the value of the old node.

// DBL_Queue Destructor
DBL_Queue::~DBL_Queue()
{
if (this->first == NULL)   // if queue is empty do nothing
    return;
else 
{
    while (this->first->getNext() != NULL)  // go through all nodes and delete them one by one
    {
        node* deletion = this->getFirst();
        this->setFirst( this->getFirst()->getNext() );
        delete deletion;
    }
}
}

Thanks in advance for the help!

  • 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-13T17:58:45+00:00Added an answer on June 13, 2026 at 5:58 pm

    Joachim’s comment:
    “Have you tried running in the debugger? It will help you locate the where the crash is, and also let you examine variables to help you see what might have caused it. However, have you thought about what happens when you enqueue the first node, meaning there is no current first node (i.e. this->getFirst() returns NULL)? You have similar problems with the dequeueing function. “

    Was the solution. my problem was i didn’t handle the insertion to an empty queue or the deletion of the last node correctly.

    Thanks all!

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
We're building an app, our first using Rails 3, and we're having to build
I'm trying to create an if statement in PHP that prevents a single post
I'm making a simple page using Google Maps API 3. My first. One marker
I am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the

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.