我不是很擅长这一点,而且我有点卡住为单个链表和与它一起的节点制作复制构造函数。包含节点的简单单链表的复制构造函数C++
这里是我的头文件:
#pragma once
#include <iostream>
using namespace std;
class Node
{
public:
int data;
Node* next;
Node()
{
next = NULL;
data = 0;
}
Node(const Node& copyNode); /*: data(copyNode.data), next(copyNode.next ? new Node(*copyNode.next) : NULL)*/
};
class SLLIntStorage
{
public:
Node* head;
Node* current;
Node* tail;
void Read(istream&);
void Write(ostream&);
void setReadSort(bool);
void sortOwn();
void print();
void mergeSort(Node**);
Node *merge(Node*, Node*);
void split(Node*, Node**, Node**);
bool _sortRead;
int numberOfInts;
SLLIntStorage(const SLLIntStorage& copying) //: head(copying.head ? new Node(*copying.head) : NULL)
{
}
SLLIntStorage(void);
~SLLIntStorage(void);
};
inline ostream& operator<< (ostream& out, SLLIntStorage& n)
{
n.Write(out);
return out;
}
inline istream& operator>> (istream& in, SLLIntStorage& s)
{
s.Read(in);
return in;
}
谁能给我一只手搭在了解如何工作的,我可以做些什么来创造呢?谢谢。
对于你可能想'更有用列表节点(INT d){未来= NULL; data = d;}',对吗? – YXD 2011-05-02 01:19:12
@Mr默认的构造函数? – 2011-05-02 12:54:27
不,对于采用一个参数的构造函数,Node的数据。 – 2011-05-05 12:05:28