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

php做的网站预览单产品网站建设

php做的网站预览,单产品网站建设,华为网络工程师认证,给别人做网站前要问些什么问题这是关于一个普通双非本科大一学生的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.zqtcl.cn/news/283181/

相关文章:

  • 网站文件验证上海推广网站公司
  • 如何免费申请网站外贸工艺品网站建设
  • 有名的wordpress网站网站开发企业培训
  • 中国建设银行绑定网站南宁seo如何做
  • 饮食类网站律师资格证报考条件
  • 昆明网站建设推广房源管理免费系统
  • jsp网站开发书籍环保网站 怎么做
  • 深圳营销型网站建设公司搜狗短网址生成
  • 如何优化购物网站建设广州seo公司排行
  • iis5.1 新建网站舆情系统的作用
  • 北京国互网网站建设公司东莞寮步搬家公司
  • 学校门户网站是什么意思做网站的意义大不大
  • 做网站卖酒网站内容建设的布局和结构
  • 效果图在哪个网站可以找比较好wordpress网站背景设置
  • 专业整站优化韩国设计公司网站
  • 网站建设与规划学的心得体会WordPress主题启用出现错误
  • 网站建设 资讯宁波东方论坛首页
  • 东莞网站制作有名 乐云践新郑州官方网
  • 网站开发经理具备什么知识调查问卷网站建设
  • 做购买网站企业宣传片制作拍摄
  • logo艺术字转换器徐州seo企业
  • 禹城网站建设公司湖州城市投资建设集团网站
  • 上海城乡住房建设厅网站asp网站怎么做301定向
  • 惠州免费网站建设上海家装10强名单
  • 新手学习做网站电子商务网站建设与维护实验报告
  • 网站建设制作设计推广上海职业技能培训机构
  • 网站不同颜色网站无障碍的建设方面空缺
  • 手机网站织梦模板it初学者做网站
  • asp做的网站怎么发布企业黄页网站源码
  • 在云服务器上搭建网站云端视差wordpress企业主题破解版