What I want to do is have a singly linked-list class with a default constructor, copy constructor, copy assignment constructer, and destructor. I barely started it because I am confused if a Node with int data and next pointer should be a separate class or the way I did it.
class list {
public:
list(): next(NULL) {} // default constructor
list(const list &t){} // copy constructor
list& operator= (const list &t) // assignment operator
~list(){} //destructor
void print()
private:
struct Node {
data x;
Node *next;
}_list;
}
Well, logically, a node is a separate structure (class), but in common implementations, the list itself is represented by the first node.
So, basically, you wouldn’t have a
listclass (and if you did, it’d just hold a pointer to the first node + the constructors/assignment operator/destructor):