我不是很擅長這一點,而且我有點卡住爲單個鏈表和與它一起的節點製作複製構造函數。包含節點的簡單單鏈表的複製構造函數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