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

做那个网站大全湘潭网站建设 搜搜磐石网络

做那个网站大全,湘潭网站建设 搜搜磐石网络,那些网站可以给产品做推广,注册公司那家网站做的比较好这是关于一个普通双非本科大一学生的C的学习记录贴 在此前#xff0c;我学了一点点C语言还有简单的数据结构#xff0c;如果有小伙伴想和我一起学习的#xff0c;可以私信我交流分享学习资料 那么开启正题 今天分享的是关于list的模拟实现#xff0c;今天只实现一部分基…这是关于一个普通双非本科大一学生的C的学习记录贴 在此前我学了一点点C语言还有简单的数据结构如果有小伙伴想和我一起学习的可以私信我交流分享学习资料 那么开启正题 今天分享的是关于list的模拟实现今天只实现一部分基础函数重点是const迭代器 1.iterator的访问 由于访问方式的不同iterator的类实现*的重载同时还应该实现-的重载 T operator*() {return _node-_data; }T* operator-() {return _node-_data; } 2.自定义类型相关 当list中存储的是自定义类型时我们来看下面的代码 struct Date {int _year;int _month;int _day;Date(int year 0,int month 1,int day 1):_year(year),_month(month),_day(day){} };void Test_list2() {listDate l;l.push_back(Date(2006,9,12));l.push_back(Date(1999,5,6));listDate::iterator it l.begin();while(it ! l.end()){cout it-_year - it-_month - it-_day endl;it;} } 很明显如果要通过it访问_year或_month_day应该是it--_year 第一次-通过it访问到Date第二次-通过Date再访问到_year 而我们要写出上面说的代码是不能编译通过的vs环境下而写一次-可以编译通过这是因为为了增强代码的可读性编译器在这里特殊处理了不需要我们写两次一次即可 3.const迭代器 实际运用中我们难免遇到const迭代器的存在 const迭代器是const对象的迭代器实际运用中我们不会自己创建const对象因为没有实际意义而在一些函数调用中难免出现const修饰的情况这个时候const迭代器的存在就不可或缺了 对于const与非const的存在我们需要对模板进行一些改造 typedef __list_iteratorT, T, T* iterator; typedef __list_iteratorT, const T, const T* const_iterator; 对应的有下面这些迭代器相关函数 iterator begin() {return iterator(_head-_next); }iterator end() {return iterator(_head); }const_iterator begin() const {return const_iterator(_head-next); }const_iterator end() const {return const_iterator(_head); } 下面是完整的代码以及测试代码 #includeiostream #includelistusing namespace std;namespace wkl {templateclass Tstruct __list_node{__list_node* _next;__list_node* _prev;T _data;__list_node(const T x T()):_next(nullptr),_prev(nullptr),_data(x){}};// T T T*templateclass T, class Ref, class Ptrstruct __list_iterator{typedef __list_nodeT Node;typedef __list_iteratorT, Ref, Ptr Self;Node* _node;__list_iterator(Node* node nullptr):_node(node){}Ref operator*(){return _node-_data;}Ptr operator-(){return _node-_data;}Self operator(){_node _node-_next;return *this;}Self operator(int){Self tmp(*this);_node _node-_next;return tmp;}Self operator--(){_node _node-_prev;return *this;}Self operator--(int){Self tmp(*this);_node _node-_prev;return tmp;}bool operator!(const Self it) const {return _node ! it._node;}bool operator(const Self it) const {return _node it._node;}templateclass Tclass list{typedef __list_nodeT Node;public:typedef __list_iteratorT, T, T* iterator;typedef __list_iteratorT, const T, const T* const_iterator;list(){_head new Node;_head-_next nullptr;_head-_prev nullptr;}~list(){clear();delete[] _head;_head nullptr;}void clear(){iterator it begin();while (it ! end()){erase(it);}}iterator begin(){return iterator(_head-_next);}iterator end(){return iterator(_head);}const_iterator begin() const{return const_iterator(_head-next);}const_iterator end() const{return const_iterator(_head);}void push_back(const T x){Node* tail _head-_prev;Node* newnode new Node(x);newnode-_next _head;newnode-_prev tail;tail-_next newnode;_head-_prev newnode;}private:Node* _head;};};void Test_list1(){listint l;l.push_back(1);l.push_back(2);l.push_back(3);l.push_back(4);listint::iterator it l.begin();while (it ! l.end()){cout *it ;it;}cout endl;}struct Date{int _year;int _month;int _day;Date(int year 0,int month 1,int day 1):_year(year),_month(month),_day(day){}};void Test_list2(){listDate l;l.push_back(Date(2006,9,12));l.push_back(Date(1999,5,6));listDate::iterator it l.begin();while(it ! l.end()){cout it-_year - it-_month - it-_day endl;it;}} void list_print(const listint l){listint::const_iterator it l.begin();while (it ! l.end()){//*it 1;cout *it ;it;}cout endl;}void Test_list3(){listint l;l.push_back(1);l.push_back(2);l.push_back(3);l.push_back(4);l.push_back(5);list_print(l);} }int main() {wkl::Test_list3();return 0; }新手写博客有不对的位置希望大佬们能够指出也谢谢大家能看到这里让我们一起学习进步吧
http://www.pierceye.com/news/88159/

相关文章:

  • 平面设计和建设网站的区别建设商务网站需要哪些步骤
  • 大型网站开发软件亚马逊国际站官网
  • 做网站是先做后台还是前端青岛网站关键词排名优化
  • 企业网站建设的原则商城网站建设的注意事项
  • 网站建设审核大访问量的网站怎么做优化
  • wordpress如何导入牛商网网站做seo好么
  • 开网站成本中国三安建设网站
  • 网站建设无法访问网站做特产的网站开张怎么宣传
  • 濮阳网站优化新乐市住房和城乡建设局网站
  • 河北廊坊做网站定制网站建设成本
  • 网站跨平台北京响应式网站开发
  • 搜索引擎推广预算郑州网站推广优化公司
  • 广告公司的名字怎么起好网站内部链接优化方法
  • 西安淘宝网站建设公司哪家好禅城区电话黄页
  • 佛山建设公司网站商城网站设计服务
  • 网站怎么做谷歌推广做网站 报价
  • 安康市建设局网站vultr怎么建设影视网站
  • 分类信息网站怎么做国内永久免费crm系统破解版
  • 校友会网站建设的目的网站建设 项目背景
  • 国外租车网站模板网站建设小江网页设计
  • 唐山网站建设哪家优惠镇江网站制作哪家便宜
  • 网站怎样盗链图片网站备案网站建设方案
  • 使用wampserver做响应式网站网页设计的代码大全
  • 区块链网站开发网站logo设计理念
  • 滨海新区建设网站wordpress 模板 含数据
  • 抚州建设工程网站网站开发工资咋样
  • 企业网站建设运营的灵魂手机网站进不去怎么办
  • 做网站的项目流程公司规划发展计划书
  • 手表网站查询网站设计深圳
  • ftp怎么连接网站东营网站制作