博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[TODO]Iterator, foreach, generics and callback in C# and Python
阅读量:6712 次
发布时间:2019-06-25

本文共 1974 字,大约阅读时间需要 6 分钟。

It seems like a huge topic, so just divide it into small pieces and conquer them piece by piece, I have drawn a map for this article to guide me finish it instead of being scared by it.

Iterator

Concept of iterator is here in , so I think iterator is just like pointer in C or cursor in database.

why use iterator

Iterator is just an abstract concept and can be implemented in many different ways. But first of all, we should figure out why we need iterator and why it is important for us.

First, just think about a simple for loop in C++:

#include 
using namespace std;int main(){ for (int i = 0; i < 3; i++) cout << i << " "; cout << endl; system("pause"); return 0;}
#include 
using namespace std;int main(){ int a[] = { 1, 2, 3 }; for (int i = 0; i < 3; i++) cout << a[i] << " "; cout << endl; system("pause"); return 0;}
#include 
using namespace std;int main(){ int a[] = { 1, 2, 3 }; for (int i = 0; i < 3; i++) cout << *(a+i) << " "; cout << endl; system("pause"); return 0;}
#include 
#include
using namespace std;int main(){ vector
a; a.push_back(1); a.push_back(2); a.push_back(3); for (vector
::iterator i = a.begin(); i != a.end(); i++) cout << *i << " "; cout << endl; system("pause"); return 0;}
#include 
#include
using namespace std;int main(){ vector
a; a.push_back(1); a.push_back(2); a.push_back(3); for (auto i : a) cout << i << " "; cout << endl; system("pause"); return 0;}

In C++, if we implement a container of our own, and we want to use for loop or while loop to traverse it like basic data type, we can use iterator by implement

So first let's analysis this example in

C++ version

Python version

C# version

转载地址:http://hwolo.baihongyu.com/

你可能感兴趣的文章
备忘:修改windows远程桌面端口
查看>>
Python走一遍A-Z的字符串使用(九)
查看>>
metasploit(MSF)终端命令大全
查看>>
Linux下php安装Redis扩展
查看>>
sublime text2 汉化
查看>>
管理信息系统测试方法总结(二)
查看>>
HTML设置超链接的颜色样式
查看>>
EMC与NetApp NAS对比
查看>>
bash算数运算&命令引用
查看>>
OpenLDAP限制用户登录主机
查看>>
高斯滤波器平滑图像代码
查看>>
分布式爬虫技术架构
查看>>
计费程序(服务器)
查看>>
Javascript的冒泡排序和二分查找
查看>>
Unity优化
查看>>
Linux下常用的日志收集命令
查看>>
JAVA NIO(知识一)
查看>>
nginx添加ssl模块
查看>>
centos 6.4 重启分区故障
查看>>
linux系统的启动流程
查看>>