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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:42:50+00:00 2026-06-05T09:42:50+00:00

For a project, im trying to set up a linked list object so that

  • 0

For a project, im trying to set up a linked list object so that it can be initialized with an explicit value constructor. I want it to look like this:

WORD you("you");//where the object you's linked list now contains y o u;

but when I print out the object you, all i see is this symbol “=”
and when I print out the length of you, I get -858993459

Here is my explicit value constructor, can someone tell me what I am doing wrong?

WORD::WORD(string s)
{
front = 0;
int i = 0;
int len = s.length();

if(front == 0)
{   
    front = new alpha_numeric;
    alpha_numeric *p = front;

    while(s[i] <= len)
    {
        p -> symbol = s[i];
        p -> next = new alpha_numeric;
        p = p -> next;
        p -> symbol = s[i++];
    }
    p -> next = 0;
}
}

Here is the class declaration file if it helps

#include <iostream>
#include <string>

using namespace std;
#pragma once

class alpha_numeric //node
{
public:
char symbol; //data in node
alpha_numeric *next;//points to next node
};

class WORD
{
public:
WORD(); //front of list initially set to Null
WORD(const WORD& other);
WORD(string s); //***EXPLICIT VALUE CONSTRUCTOR
bool IsEmpty(); //done
int Length();
void Add(char); //done
//void Insert(WORD bword, int position);
//void operator=(char *s);

friend ostream & operator<<(ostream & out, const WORD& w);//done

private:
alpha_numeric *front; //points to the front node of a list
int length;
};
  • 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-05T09:42:52+00:00Added an answer on June 5, 2026 at 9:42 am

    You never set length, so that’s why it’s garbage. As luthien256 ahd LihO pointed out, your while loop is also wrong, and the if (front == 0) test makes no sense.

    Finally, the p -> symbol = s[i++]; is not needed. Just increment i.

    Try this:

    class alpha_numeric //node
    {
    public:
    char symbol; //data in node
    alpha_numeric *next;//points to next node
    };
    
    class WORD
    {
    public:
    WORD(); //front of list initially set to Null
    WORD(const WORD& other);
    WORD(string s); //***EXPLICIT VALUE CONSTRUCTOR
    bool IsEmpty(); //done
    int Length() { return length; }
    alpha_numeric *Front() { return front; }
    void Add(char); //done
    //void Insert(WORD bword, int position);
    //void operator=(char *s);
    
    friend ostream & operator<<(ostream & out, const WORD& w);//done
    
    private:
    alpha_numeric *front; //points to the front node of a list
    int length;
    };
    
    WORD::WORD(string s)
    {
      front = 0;
      int i = 0;
      int len = s.length();
      length = len;
      if (length == 0) {
        front = NULL;
        return;
      }
      front = new alpha_numeric;
      alpha_numeric *p = front;
    
      while(i < len)
      {
          p -> symbol = s[i];
          if (i != len - 1) {
            p -> next = new alpha_numeric;
            p = p -> next;
          }
          else
            p -> next = NULL;
          ++i;
      }
    }
    
    
    int main() {
      WORD you("you");
      alpha_numeric* front = you.Front();
      while(front != NULL) {
        cout<<(front->symbol)<<endl;
        front = front->next;
      }
      cout<<you.Length()<<endl;
      return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to set up some like buttons to a project. These buttons live
Trying to set up a new project, and running into a weird issue. I
I'm trying to set up Jenkins-ci for a project using GitHub. I've already set
I'm trying to set up a development environment for a legacy Rails 2.3.8 project.
this is for a small project of mine, I'm trying to set the current
I am working on a legacy Java Enterprise server project, trying to set up
I've set up a project with an SDF local database file and am trying
I'm trying to get a new Enterprise Application Project set up in Eclipse using
I'm trying to set up my Netbeans IDE so that it is capable of
for a project i'm currently working on, im trying to pass a set of

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.