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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:26:57+00:00 2026-06-05T17:26:57+00:00

For an assignment, I need to add one objects linked list to the back

  • 0

For an assignment, I need to add one objects linked list to the back of another. I have this:

WORD you("you");//where you's linked list now contains y o u
WORD are("are");//where are's linked list now contains a r e

and I want to do this:

you.Insert(are,543);//(anything greater they the current objects length is
                    //attached to the back. So that 543 can be anything > you's length

so Now, you’s linked linked list should contain:

y o u a r e

I was able to insert in the front, and anywhere in between the letters, but when I try to insert in the back the program crashes instantly. Can someone please help me figure out what is wrong? I tried using the debugger and it points to one line, but I cant figure out what is wrong. I’ve marked the line as a coming in the function:

void WORD::Insert(WORD & w, int pos)
{
if(!w.IsEmpty())
{
    alpha_numeric *r = w.Cpy();
    alpha_numeric *loc;

    (*this).Traverse(loc,pos);//pasing Traverse a pointer to a node and the     position in the list

    //if(loc == 0)
    //{
    //  alpha_numeric *k = r;//k is pointing to the begin. of the copied words list
    //  while(k -> next != 0)
    //  {
    //      k = k -> next;//k goes to the back 
    //  }
    //  k -> next = front;//k(the back) is now the front of *this
    //  front = r;//front now points to r, the copy
    //}
    else if(loc == back)
    {

        back -> next = r; //<<<-------DEBUGGER SAYS ERROR HERE?
        length += w.Length();
        while(back -> next!= 0)
        {
            back = back -> next;
        }
    }
    /*else
    {
        alpha_numeric *l = r;

        while(l -> next != 0)
        {
            l = l -> next;
        }
        l -> next = loc -> next;
        loc -> next = r;
    }
    length += w.Length();
}*/
}

Also, here is the Traverse function I used if it helps

void WORD::Traverse(alpha_numeric * & p, const int & pos)
{
if(pos <= 1)
{
    p = 0;
}
else if( pos > (*this).Length())
{
    p = back;
}
else
{
    p = front;
    for(int i = 1; i < pos - 1; i++)
    {
        p = p -> next;
    }
}

}

I DECLARED BACK AS A POINTER IN THE PRIVATE SECTION OF THE CLASS. *back

This is how I put it in the constructor

WORD::WORD()
{
alpha_numeric *p;

front = new alpha_numeric;
front = 0;
length = 0;
back = front;

for(p = front; p != 0; p = p -> next)
{
    back = back -> 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-05T17:26:59+00:00Added an answer on June 5, 2026 at 5:26 pm

    *back is not pointing to the correct node in the Traverse function. It should look like this:

    else if( pos > (*this).Length())
    {
        alpha_numeric *k = (*this).front;
        while( k -> next != 0)
        {
            k = k -> next;
        }
        back = k;
        p = back;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For a homework assignment i need to create a List<T> , add objects to
Ok, this is homework. I have an arraylist assignment to add, display, search and
As a part of the programming Assignment, I have to maintain a linked list
Hello is have a question for a school assignment i need to : Read
I have a homework assignment where I need to take input from a file
Hi I have a homework assignment where I need to implement an intersection of
this is for an assignment at school, where I need to determine the size
I've been working on this assignment, where I need to read in records and
Hello I have a homework assignment where I need to read two matrix .txt
I need to add two polynomials together using a recursive method. This is for

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.