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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:44:49+00:00 2026-06-18T12:44:49+00:00

I created a linked list called e. I used a copy constructor to create

  • 0

I created a linked list called e. I used a copy constructor to create e2 but for some reason , the programme always crashes when i try to print e2. Can someone explain to me and help me solve this for me thanks.

#include <iostream>
#include <ctime>
#include <cmath>

using namespace std;

class Element
{

public: Element();//constructor
    Element(const Element&); //copy constructor

    //Element& Element::operator =(const Element & from);
     void Addelement(int row, int col, int value);
     void swap(int num,int x, int arr[100]);
     void printelement();
     void rowordermajor();

private:


    typedef Element* ElementPtr;


        int row;
        int col;
        int value;
        ElementPtr next; 


    ElementPtr head;

    bool comparegreater(ElementPtr temp1, ElementPtr temp2);

};

int main()
{
Element e;
for (int i=0;i<5;i++)
{
    e.Addelement(i,i,i);



}
e.printelement();

Element e2(e);
//e2.printelement();

system("PAUSE");

}



Element::Element()//normal constructor
{
head=NULL;
}

Element::Element(const Element& e)
{
   this->row=e.row;
   this->col=e.col;
   this->value=e.value;
   this->next=e.next;


}

void Element::Addelement(int row, int col, int value )
{

ElementPtr temp= new Element;
temp->row=row;
temp->col=col;
temp->value=value;
temp->next=head;
head=temp;
 }



         void Element::printelement()//why does it print backwards
{
ElementPtr temp=head;

while (temp != NULL)
{
    cout<<"( "
        <<temp->row
        <<" , "
        <<temp->col
        <<" , "
        <<temp->value
        <<" ) ";

    cout<<endl;

    temp=temp->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-18T12:44:50+00:00Added an answer on June 18, 2026 at 12:44 pm

    Because you aren’t assigning NULL (or maybe this->head = e.head;) to head when you are using the constructor with Element& e as argument.

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

Sidebar

Related Questions

I'm currently implementing a copy constructor for a Linked List class. When I create
I have implemented a Linked List into Java. I have created everything, but I
I'm trying to create a linked list class in Eclipse but I can't get
I created a linked list and when I tried to print values of the
I've already created the Binary Tree and Linked list classes, I'm just in need
Im trying to implement a destructor for the objects of linked-list Iv created. I
I have created a discount in commerce server, and linked it with a list
I create a linked list dynamically and initialize the first node in main(), and
I am trying to create a linked list where you can enter items into
I would like to know how to create a linked list of linked lists.

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.