わかりましたので、リンクされたリストのコピー コンストラクターを作成しようとしています。配列のコンストラクターをコピーする方法は知っていますが、リンクされたリストのコンストラクターは知りません。どうすればこれを行うことができるか、誰かが私にアイデアを教えてくれますか?ありがとう。
class node
{
public :
double data;
node *next; /// pointer that points to next elemnt
node () { next = NULL; data = 0; }
node (double val ) { next = NULL; data = val; }
private:
};
キュー ヘッダー
class linked_queue
{
public :
linked_queue() { front = NULL; back = NULL; ctr = 0; } /// default constructor
bool _empty();
void _size();
void _front();
void _back();
void _push(double);
void pop();
void _display();
~linked_queue(); /// destructor
linked_queue& operator= ( const linked_queue& rhs );
linked_queue( const linked_queue& other );
private :
int ctr; /// counter
node *front; /// front pointer
node *back; ///back pointer
};
編集:これは私が思いついたものです
linked_queue::linked_queue( const linked_queue& other ) {
ctr = 0;
front = NULL;
back = NULL;
node *p = other.front;
while ( p != NULL )
{
_push( p->data);
p = p->next;
}
}