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

做壁纸网站好佛山建网站永网

做壁纸网站好,佛山建网站永网,北京海淀租车公司价格,wordpress如何换域名【C模拟实现】list的模拟实现 目录 【C模拟实现】list的模拟实现list模拟实现的部分代码list模拟实现中的要点const_iterator的实现push_backoperator运算符重载iterator begin()函数 作者#xff1a;爱写代码的刚子 时间#xff1a;2023.9.3 前言#xff1a;本篇博客关于li…【C模拟实现】list的模拟实现 目录 【C模拟实现】list的模拟实现list模拟实现的部分代码list模拟实现中的要点const_iterator的实现push_backoperator运算符重载iterator begin()函数 作者爱写代码的刚子 时间2023.9.3 前言本篇博客关于list的模拟实现和模拟实现中遇到的问题 list模拟实现的部分代码 namespace test {templateclass Tstruct list_node//默认公有{list_nodeT* _next;list_nodeT* _prev;T _val;list_node(const T val T()):_next(nullptr),_prev(nullptr),_val(val){}};templateclass T,class Ref,class Ptrstruct __list_iterator{typedef list_nodeT Node;typedef __list_iteratorT, Ref, Ptr Self;Node* _node;__list_iterator(Node* nodenullptr):_node(node){}__list_iterator(const Selfl):_node(l._node){}Ref operator*(){return _node-_val;}Ptr operator-(){return _node-_val;}Self operator(){_node_node-_next;return *this;}Self operator(int){Self tmp(_node);return tmp;}Self operator--() {_node_node-_prev;return *this;}Self operator--(int) {Self tmp(*this);_node_node-_prev;return *this;}bool operator!(const Self it) const//引用时一定要注意是否要加上const防止权限放大这里需要加上{return _node!it._node;}bool operator(const Self it) const{return _nodeit._node;}};templateclass Tclass list{typedef list_nodeT Node;public:typedef __list_iteratorT, T ,T* iterator;typedef __list_iteratorT, const T ,const T* const_iterator;iterator begin(){//return _head-_next;return iterator(_head-_next);}iterator end(){//return _head;return iterator(_head);}list(){_headnew Node;_head-_prev_head;_head-_next_head;}~list(){clear();delete _head;_headnullptr;}void clear(){iterator it begin();while(it!end()){iterase(it);}}void push_back(const T x){insert(end(),x);//注意这里是end(),不是end()-1;}void pop_back(){erase(--end());}iterator insert(iterator pos, const T x){Node*newnode new Node(x);pos._node-_prev-_nextnewnode;newnode-_prevpos._node-_prev;newnode-_nextpos._node;pos._node-_prevnewnode;return newnode;}iterator erase(iterator pos){Node*tmppos._node;Node*nexttmp-_next;tmp-_prev-_nexttmp-_next;tmp-_next-_prevtmp-_prev;delete tmp;tmp nullptr;return next;}private:Node* _head;}; } list模拟实现中的要点 const_iterator的实现 我们选择使用模版参数复用iterator的类设置三个模版参数templateclass T,class Ref,class Ptr并且typedef __list_iteratorT, const T ,const T* const_iterator,具体看代码的实现 push_back push_back函数中复用了insert函数但是注意的是传入的参数是end(),并不和pop_back函数中一样传入–end(); operator运算符重载 由于迭代器的实现类使用了模版参数所以有两种类const_iterator和iterator所以在使用引用作为传入参数时需注意引用要加const防止使用const_iterator类时权限放大 iterator begin()函数 在此函数中可以使用return _head-_next;编译器会自动使用构造函数构造iterator类 附类的拷贝构造一定要使用引用并考虑是否再加上const。
http://www.zqtcl.cn/news/135435/

相关文章:

  • 网站建设流程行业现状安阳历史
  • 制作软件的网站装饰工程设计东莞网站建设
  • 如何不花钱开发网站搜索引擎营销原理是什么
  • 网站不能访问如何做冗余Wordpress手机短信
  • 深圳的设计网站公司新媒体网站建设
  • 网站title优化实搜网站建设
  • 淘宝网网页版官网优化系统软件
  • 公司找网站做宣传做账网页设计的岗位叫什么
  • 门户网站区别视频上传下载网站建设
  • 企业局域网组建与网站建设域名备案的网站名称
  • 广西学校论坛网站建设网站建设得花多少钱
  • 装修公司网站源代码网站建设岗位周计划
  • 有没有专门学做婴儿衣服的网站org.wordpress utils
  • 网站关键词 提醒哪个网站做视频有钱挣
  • 建设企业网站注意事项菜篮网网站开发技术
  • 怎么把图片做超链接到网站wordpress 配置模板
  • 湘潭网站seo惠州市建设厅网站
  • 广州外贸网站效果百度竞价开户需要多少钱
  • 广州做手机网站信息附近卖建筑模板市场
  • 怎么看网站开发语言信息dw网站建设视频下载
  • 做网站虚拟主机多少钱wordpress中category参数
  • 山东省建设执业师网站建设网站图片
  • 网站建设的安全可行性网站建设教学设计
  • 网站架设建设动易门户网站价格
  • 公司快速建站商城网站建设讯息
  • it公司做网站用什么软件鲁中网站
  • 制作属于自己的app教程北京和隆优化招聘
  • wordpress会员卡系统青岛百度优化
  • 网站的管理系统网站权限配置
  • 龙岗高端网站建设在进行网站设计时