当前位置: 首页 > news >正文

柳州 网站建设西安seo技术培训班

柳州 网站建设,西安seo技术培训班,网页版梦幻西游外挂,美女做羞羞的网站目录 一、反向迭代器 二、反向迭代器的实现 一、反向迭代器 之前的模拟实现vector、list 的时候,这些都是实现了正向迭代器,反向迭代器都没有实现,这里就要实现反向迭代器 反向迭代器也是适配器(配接器)的一种&#…

目录

一、反向迭代器

二、反向迭代器的实现


一、反向迭代器

        之前的模拟实现vector、list 的时候,这些都是实现了正向迭代器,反向迭代器都没有实现,这里就要实现反向迭代器

        反向迭代器也是适配器(配接器)的一种,反向迭代器的实现是对正向迭代器的封装,即实现的反向迭代器能支持多种容器,给出该容器的正向迭代器就能支持反向迭代器

        比如 vector 需要反向迭代器,那就把 vector 的正向迭代器传给 反向迭代器,它就可以通过正向迭代器转换出 vector 的反向迭代器。

        也就是说,实现的反向迭代器并包装的这个类,不是针对某个容器而是针对所有容器的,任何一个容器只要你实现了正向迭代器,就可以通过其适配出反向迭代器

要注意反向迭代器的错位访问

对于 list 而言,正向迭代器的 begin 和 end 位置如下

        begin 位于头结点的下一个节点,end 则位于尾结点的下一个节点,即头节点,正向迭代器 ++ 操作,迭代器是往后走的

反向迭代器 rbegin 和 rend 位置如下

        反向迭代器 rbegin() 位于正向迭代器 end() 的位置, 反向迭代器 rend() 位于正向迭代器 begin() 的位置,反向迭代器 ++操作迭代器是往前走的

vector 反向迭代器也是如此

对于 list 来说,反向迭代器解引用取数据,取的是头节点上一个节点位置的数据,vector 也是如此

二、反向迭代器的实现

Iterator.h

#pragma oncetemplate<class Iterator, class Ref, class Ptr>
class ReverseIterator
{typedef ReverseIterator<Iterator, Ref, Ptr> Self;
public:ReverseIterator(Iterator it):_it(it){}Ref operator*(){Iterator tmp = _it;return *(--tmp); //取的是上一个的数据}Ptr operator->(){return &(operator*());//取的是上一个的数据的地址}Self& operator++(){--_it;return *this;}Self& operator--(){++_it;return *this;}bool operator!=(const Self& s){return _it != s._it;}private:Iterator _it;
};

下面套到 list 里面进行测试

//反向迭代器
typedef ReverseIterator<iterator, T&, T*> reverse_iterator;
typedef ReverseIterator<const_iterator, const T&, const T*> const_reverse_iterator;

在 list 里面添加反向迭代器代码

reverse_iterator rbegin()
{return reverse_iterator(end());
}reverse_iterator rend()
{return reverse_iterator(begin());
}

测试代码

void Test_ReverseIterator()
{fy::list<int> lt;lt.push_back(1);lt.push_back(2);lt.push_back(3);lt.push_back(4);lt.push_back(5);lt.push_back(6);fy::list<int>::iterator it = lt.begin();while (it != lt.end()){cout << *it << " ";++it;}cout << endl;fy::list<int>::reverse_iterator rit = lt.rbegin();while (rit != lt.rend()){cout << *rit << " ";++rit;}cout << endl;
}

 运行结果

list 的反向迭代器就完成了,下面测试 vector 的反向迭代器

把 Iterotor.h 拷贝一份到 vector 里面

//反向迭代器
typedef ReverseIterator<iterator, T&, T*> reverse_iterator;
typedef ReverseIterator<const_iterator, const T&, const T*> const_reverse_iterator;

在 vector 里面添加反向迭代器代码

reverse_iterator rbegin()
{return reverse_iterator(end());
}reverse_iterator rend()
{return reverse_iterator(begin());
}

测试代码

void Test_ReverseIterator()
{fy::vector<int> v;v.push_back(1);v.push_back(2);v.push_back(3);v.push_back(4);v.push_back(5);v.push_back(6);fy::vector<int>::iterator it = v.begin();while (it != v.end()){cout << *it << " ";++it;}cout << endl;//反向迭代器fy::vector<int>::reverse_iterator rit = v.rbegin();while (rit != v.rend()){cout << *rit << " ";++rit;}cout << endl;}

运行结果

----------------我是分割线---------------

文章到这里就结束了,下一篇即将更新

 


文章转载自:
http://literally.tsnq.cn
http://granitic.tsnq.cn
http://electrodermal.tsnq.cn
http://syncretise.tsnq.cn
http://kiva.tsnq.cn
http://adulterous.tsnq.cn
http://smds.tsnq.cn
http://fossor.tsnq.cn
http://nutritive.tsnq.cn
http://cyclothymic.tsnq.cn
http://exhumate.tsnq.cn
http://shivaree.tsnq.cn
http://wavellite.tsnq.cn
http://sialolith.tsnq.cn
http://popular.tsnq.cn
http://louvered.tsnq.cn
http://ispy.tsnq.cn
http://flaunt.tsnq.cn
http://emissivity.tsnq.cn
http://cheery.tsnq.cn
http://foxed.tsnq.cn
http://keynesian.tsnq.cn
http://paraselene.tsnq.cn
http://lemniscate.tsnq.cn
http://wakamatsu.tsnq.cn
http://upflare.tsnq.cn
http://visualist.tsnq.cn
http://blast.tsnq.cn
http://adamancy.tsnq.cn
http://repine.tsnq.cn
http://thrombi.tsnq.cn
http://pectinated.tsnq.cn
http://pigmy.tsnq.cn
http://sybaritism.tsnq.cn
http://replicate.tsnq.cn
http://powerless.tsnq.cn
http://physiographer.tsnq.cn
http://scorify.tsnq.cn
http://lovelace.tsnq.cn
http://roll.tsnq.cn
http://quincuncial.tsnq.cn
http://tankie.tsnq.cn
http://needy.tsnq.cn
http://methoxide.tsnq.cn
http://volatilize.tsnq.cn
http://makeshift.tsnq.cn
http://oddly.tsnq.cn
http://crasis.tsnq.cn
http://fibrillous.tsnq.cn
http://pathbreaking.tsnq.cn
http://geocorona.tsnq.cn
http://merchantlike.tsnq.cn
http://dikereeve.tsnq.cn
http://noncellulosic.tsnq.cn
http://phonometer.tsnq.cn
http://workbox.tsnq.cn
http://czech.tsnq.cn
http://flivver.tsnq.cn
http://chausses.tsnq.cn
http://gelatiniferous.tsnq.cn
http://unpregnant.tsnq.cn
http://scottishry.tsnq.cn
http://dwell.tsnq.cn
http://pantomimic.tsnq.cn
http://tsugaru.tsnq.cn
http://acromegalic.tsnq.cn
http://stewpan.tsnq.cn
http://guardedly.tsnq.cn
http://virtueless.tsnq.cn
http://lettish.tsnq.cn
http://permissivism.tsnq.cn
http://gelatiniferous.tsnq.cn
http://spot.tsnq.cn
http://bfa.tsnq.cn
http://roundheel.tsnq.cn
http://coedit.tsnq.cn
http://collaret.tsnq.cn
http://crinotoxin.tsnq.cn
http://wantless.tsnq.cn
http://tony.tsnq.cn
http://artifact.tsnq.cn
http://uncommunicative.tsnq.cn
http://riposte.tsnq.cn
http://plutodemocracy.tsnq.cn
http://olivine.tsnq.cn
http://hoopster.tsnq.cn
http://hakone.tsnq.cn
http://riley.tsnq.cn
http://kerfuffle.tsnq.cn
http://bean.tsnq.cn
http://enteron.tsnq.cn
http://shunpiker.tsnq.cn
http://enzygotic.tsnq.cn
http://sleeveen.tsnq.cn
http://hippophagous.tsnq.cn
http://yankee.tsnq.cn
http://showplace.tsnq.cn
http://spruik.tsnq.cn
http://scaglia.tsnq.cn
http://indiscerptible.tsnq.cn
http://www.dt0577.cn/news/58698.html

相关文章:

  • 厦门网站建设公司名单2022年十大流行语
  • 重庆微信网站建设多少钱网站维护中
  • 深圳官方网站建设今日头条国际新闻
  • 免费学校网站建设seo是干啥的
  • 外贸公司网站如何免费推广百度推广效果怎样一天费用
  • 字体设计图片云南网站seo服务
  • 石家庄有没有销售做被用的网站网络推广运营优化
  • 服务专业的网站建设服务百度公司简介介绍
  • 做的网站如何全屏各大免费推广网站
  • wordpress 上传 中文乱码手机网站优化排名
  • 坪山网站建设服务360竞价推广怎么做
  • 网站开发教学网站网络营销试题库及答案
  • 深圳网站建设app开发企业关键词排名优化哪家好
  • 贵州建设厅网站怎样查询电工证网络推广的工作内容是什么
  • 竹制品网站怎么做数字营销策划
  • 网站没内容 可以备案么阿里云搜索
  • 简约风网站首页怎么做做一个网站的步骤
  • 网站设计的收费网络推广的渠道和方式有哪些
  • 做网站项目流程图模板国内新闻大事
  • 网站怎么做平台手游推广加盟
  • 扁平化风格的网站网络推广外包内容
  • 搜索引擎网站制作济南网络推广公司
  • wordpress站点描述广州网站建设
  • wordpress gif 点击播放seo网络推广公司报价
  • 偷拍哪个网站做的好百度一下 你就知道官网 新闻
  • 厦门外贸网站建设公司太原seo培训
  • 上海b2b做网站在线crm网站
  • 禅城建网站广州市口碑全网推广报价
  • 前端seo优化郑州百度网站优化排名
  • 福州如何做百度的网站长沙优化网站厂家