64,662
社区成员
发帖
与我相关
我的任务
分享
template <class T>
class list<T>::iterator{
public:
list<T>::iterator &operator++() {
pn=pn->next;
return *this;
}
private:
Node<T> *pn; //指向当前节点的指针
};
list nlist;//假设已经初始化
list<int>::iterator iter;
iter=nlist.begin();
while(iter != nlist.end()) {
cout<<*iter<<endl;
iter++;
}
int a[6]={1, 2, 3, 4, 5};
int *pa=a;//视pa为数组的迭代器
while( pa!=&(a[5]) ) {
cout<<*pa<<endl;
pa++;
}
struct node
{
int value;
node *next;
};
int main()
{
node nodes[5];
for (int i=0;i<5;++i)
{
nodes[i].value = i;
if (i == 4)
{
nodes[i].next = 0;
}
else
{
nodes[i].next = nodes + i + 1;
}
}
for (node* iter=nodes;iter != 0;iter=iter->next)
{
cout<<iter->value<<endl;
}
return 0;
}