我正在尝试获得一个可以调用 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