数据结构–单链表
本以为单链表会比双链表简单,结果花了好几个晚上才把它搞定…
不带头节点的单链表,基本功能其实不难实现,但是迭代器调试了半天
#pragma once
#include <iostream>
using namespace std;
template <typename Type>
struct Node
{
Type data;
Node<Type> *next;
Node<Type>(Node<Type> *ptr = NULL) {
next = ptr; };
Node<Type>(const Type &_data, Node<Type> *ptr = NULL) {
data = _data; next = ptr; }
};
template <typename Type> class SLLIter;
template <typename Type>
class SLList
{
private:
Node<Type> *head;
public:
friend class SLLIter<Type>;
/
// Function : Constructor
// Notes : constructs an empty list
/
SLList()
{
head =NULL;
};
/
// Function : Destructor
// Notes : Destroys the list
/
~SLList()
{
clear();
delete head;
};
/
// Function : Assignment Operator
/
SLList<Type>& operator=(const SLList<Type>& that)
{
if (this == &that) {
return *this;
}
else {
clear();
if (that.head == NULL