按照自己的理解自己写的关于迭代器原理基本功能实现代码!不足之处请大家多多指教!
![微笑](http://static.blog.csdn.net/xheditor/xheditor_emot/default/smile.gif)
#include <iostream>
#define MAX 10
using namespace std;
/*节点类*/
class Node
{
public:
int data;
Node *next;
};
/*迭代器类*/
class Iterator
{
public:
Iterator():ptr(NULL){}
Iterator(Node *node):ptr(node){}
int operator *()
{
return ptr->data;
}
Iterator & operator ++()
{
ptr = ptr->next;
return *this;
}
Iterator & operator ++(int)
{
Iterator *temp = NULL;
temp = this;
ptr = ptr->next;
return *temp;
}
Node *get_ptr()
{
return ptr;
}
private:
Node *ptr;
};
/*链表类*/
class Link
{
public:
Link(Node *node = NULL):head(NULL){}
void creat_link(); /*创建链表*/
void print(); /*打印链表