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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:14:13+00:00 2026-06-04T06:14:13+00:00

I am trying to do a linked list of int values. I add 3

  • 0

I am trying to do a linked list of int values. I add 3 int values to list, and I print them but my problem after print the 3 values, the program goes back in to print function to print a 4th one because (tempNode != NULL) gives true but it should be NULL after printing 3 values, so it gives me access violation reading error in the print method at cout << "index " << size-- << ", value: "<< tempNode->num << endl;

It is going beyond my list nodes, but I have no idea where am doing wrong.

Please help, 2 days am trying to figure this out.

code below.

IntList::IntList()
{
    first = NULL;
    last = NULL;
    size = 0;
}


 IntList::Node::Node(const int& info, Node* next = NULL)
 {
    num = info;
    next = next;
 }


 IntList::~IntList()
 {
    Node* tempNode = first;
    while ( tempNode != NULL )
    //for(int i = 0; i < size; i++)
    {
        Node* nextNode = tempNode->next;
        delete tempNode;
        tempNode = nextNode;
    }

    first = last = NULL;
    size = 0;
  }


IntList::IntList(const IntList& wl)
{
     cout << "here word list copy conts " << endl;

     first = last = NULL;
     size = wl.size;
     if(wl.first != NULL){

        Node* tempNode = wl.first;
        for(int i = 0; i < wl.size; i++)
        {
              addLast(tempNode->num);
              tempNode = tempNode->next;
        }
     }
}


IntList& IntList::operator = (const IntList& wl)
{
    cout << "here word list =" << endl;
    if(this == &wl)
        return *this;

    Node* tempNode = first;
    while ( tempNode != NULL )
    {
        Node* nextNode = tempNode->next;
        delete tempNode;
        tempNode = nextNode;
    }

    first = NULL;
    last = NULL;

    if(wl.first != NULL)
    {
        for(int i = 0; i < wl.size; i++)
        {
           addLast(tempNode->num);
           tempNode = tempNode->next;
           size++;
    }
}

return *this;
}

 void IntList::addFirst(int& winfo)
{
    Node* firstNode = new Node(winfo);
    //Node firstNode(winfo);
    if(first == NULL) 
    {
        first = last = firstNode;
    }
    else 
    {
        firstNode->next = first;
        first = firstNode;  
    }
    //increment list size
    size++;
}

void IntList::print(ostream& out)
{
    Node* tempNode = first;
    while ( tempNode != NULL )
    {
        out << "\t";
        cout << "index " << size-- << ", value: "<< tempNode->num << endl;
        tempNode = tempNode->next;
    }
 }
  • 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-04T06:14:14+00:00Added an answer on June 4, 2026 at 6:14 am

    The next parameter of the Node constructor shadows its next member, so next = next is assigning to the parameter.
    Rename one of them.

    Also, don’t modify size while you’re printing.

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

Sidebar

Related Questions

I am trying simple linked list Collection program, but it is not giving me
I am trying to print the reverse linked list. But I am getting only
I'm trying to illustrate a doubly linked list problem. this is from an old
I'm trying to implement a linked list but get an error when compiling: intSLLst.cpp:38:
I am trying to write a code for a linked list but when I
I'm trying to reverse a linked list by using C++ and then print out
I'm basically trying to create a linked list from a text file and add
Im trying to create linked-list insert function that takes a list (or more correctly
I am trying to create a linked list where you can enter items into
Im trying to implement a destructor for the objects of linked-list Iv created. I

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.