insert_back を呼び出すことができる機能する関数を取得しようとしています。リストの最後に値を挿入します
これまでのところ、私はコードを持っていますが、困惑していると思います。
template <class Object>
void List<Object>::insert_back( const Object& data ) {
ListNode<Object>* newnode = new ListNode<Object>( data, head->getNext() );
if (!head) {
head = newnode;
return;
}
while (head->getNext()) {
continue;
}
head->setNext( newnode );
}
これは何も返さず、insert_back を呼び出すとプログラムが停止します。
.H ファイル
#ifndef LIST_H
#define LIST_H
#include <iostream>
#include "ListNode.h"
#include "ListIterator.h"
namespace cs20 {
template <class Object>
class List {
public:
List();
List( const List& rhs );
~List();
bool isEmpty() const;
bool isIncreasing() const;
void makeEmpty();
ListIterator<Object> zeroth() const;
ListIterator<Object> first() const;
void insert( const Object& data,
const ListIterator<Object> &iter );
void insert( const Object& data );
void insert_back( const Object& data );
ListIterator<Object> findPrevious( const Object& data ) const;
void remove( const Object& data );
const List& operator =( const List& rhs );
const List& operator <<( const List& rhs );
private:
ListNode<Object> * head;
};
}
#endif