Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

How to implement copy constructor for very simple singly linked list in C++?

I am having quite a bit of difficulty understanding how to implement a copy constructor for a singly linked list in C++. Heres is the code I have for the implementation:

--------------------------------------…

struct node {

string value;

node * next;

};

class strSet {

private:

node * first //points to the first node of the object;

public:

...

strSet (const strSet& copy);

...

};

--------------------------------------…

I am having difficulty implementing this copy constructor. Can anyone shed some light? I'm not sure what to put in the body.

strSet (const strSet& copy) {

...

}

The other public member functions don't relate to the copy constructor. I'm suppose to do a deep copy manually.

Do I need to make 1 or 2 temp variables? I know I need one that goes through the list we're copying from because we don't want to change the original variable.

1 Answer

Relevance
  • 1 decade ago
    Favorite Answer

    Did you at least TRY reading the replies to you previous duplicate posts?

Still have questions? Get your answers by asking now.