小编Pat*_*ick的帖子

在单链表 C++ 中实现复制构造函数

我有一个 C++ 代码:

#include <iostream>
using namespace std;
struct Node;

typedef Node *NodePtr;

struct Node
{
    int Item;
    NodePtr Next;
};

class LinkedList
{
public:
    LinkedList();                   // default constructor
    ~LinkedList();                  // destructor
    void AddTail(int);              // adds item to tail
private:
    NodePtr Head;
};

LinkedList::LinkedList()
{
    Head = NULL; //declare head as null
}
//Adding on tail
void LinkedList::AddTail(int Item)
{
    NodePtr Crnt;
    NodePtr node = new Node;
    node->Item = Item;
    node->Next = NULL;
//if head is in null declare the …
Run Code Online (Sandbox Code Playgroud)

c++ constructor destructor linked-list copy-constructor

3
推荐指数
1
解决办法
2万
查看次数