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

发布网站的两种方法青柠影院免费观看电视剧高清

发布网站的两种方法,青柠影院免费观看电视剧高清,北京计算机培训机构,即时设计list库实现的要点&#xff1a; 构建list类时&#xff0c;需要同时构建struct Node来存储节点信息&#xff0c;list类中只存储哨兵位节点信息&#xff0c;迭代器类需要template<T,Ptr,Ref>来构建const和非const迭代器&#xff0c;迭代器中也是存储节点信息。反向迭代器也…

list库实现的要点:

构建list类时,需要同时构建struct Node来存储节点信息,list类中只存储哨兵位节点信息,迭代器类需要template<T,Ptr,Ref>来构建const和非const迭代器,迭代器中也是存储节点信息。反向迭代器也是同样道理,但是可以用迭代器来构建反向迭代器。具体代码如下 

#include<iostream>
#include<assert.h>
#include<algorithm>
using namespace std;template<class T>
struct __list_node
{__list_node(const T& val = T()):_data(val),_prev(nullptr),_next(nullptr){}__list_node* _prev;__list_node* _next;T _data;
};//构建每个节点//构建迭代器struct
template<class T, class Ptr, class Ref>
struct __list_iterator
{typedef __list_node<T> Node;typedef __list_iterator<T, Ptr, Ref> Self;Node* _node;//成员变量还是节点,只是在成员函数做手脚__list_iterator(Node* val ):_node(val){}Self& operator++(){_node = _node->_next;return *this;}Self operator++(int)//后置{Self tmp = *this;++(*this);return tmp;}Self& operator--(){_node = _node->_prev;return *this;}Self operator--(int){Self tmp = *this;--(*this);return tmp;}Ptr operator->(){return &(_node->_data);}Ref operator*(){return _node->_data;}bool operator!= ( const Self& val ){return !(_node == val._node);}};
template<class T,class Ptr,class Ref>
struct __list_reverse_iterator
{typedef __list_iterator<T, T*, T&> iterator;typedef __list_reverse_iterator<T, T*, T&> Self;iterator _it;__list_reverse_iterator(iterator it):_it(it){}Self operator++(){_it = _it._node->_prev;return *this;}T& operator*(){return _it._node->_data;}bool operator!=(const Self& rit){return !(_it._node == rit._it._node);}};//构建双向带头循环链表
template<class T>
class list
{typedef __list_node<T> Node;
public:typedef __list_iterator<T,T*,T&> iterator;typedef __list_iterator<T, const T*, const T&> const_iterator;typedef __list_reverse_iterator<T, T*, T&> reverse_iterator;reverse_iterator rbegin(){return reverse_iterator(--end());}reverse_iterator rend(){return reverse_iterator(end());}iterator begin(){return iterator(_phead->_next);}const_iterator begin()const{return const_iterator(_phead->_next);}iterator end(){return iterator(_phead);}const_iterator end()const{return const_iterator(_phead);}list()//开头空间,初始化{_phead = new Node;_phead->_next = _phead;_phead->_prev = _phead;}~list(){clear();delete _phead;_phead = nullptr;}//拷贝构造(先创建一个哨兵位,然后再pushback)list(const list<T>& l){_phead = new Node;_phead->_next = _phead;_phead->_prev = _phead;for (auto& x : l){push_back(x);}}list<T>& operator=(const list<T>& l){list<T> tmp(l);swap(_phead, tmp._phead);return *this;}//尾插入void push_back(const T& val){//Node* tail = _phead->_prev;//Node* newnode = new Node(val);更变链接//tail->_next = newnode;//newnode->_prev = tail;//newnode->_next = _phead;//_phead->_prev = newnode;insert(end(), val);}//头插void push_front(const T& val){insert(begin(), val);}//头删除void pop_front(){erase(begin());}//尾删除void pop_back(){erase(--end());}//清空节点(除了哨兵位,都清除)void clear(){iterator it = begin();while (it != end()){it = erase(it);}}//随机插入void insert(iterator pos, const T& val){Node* pcur = pos._node;Node* prev = pcur->_prev;Node* newnode = new Node(val);//构建联系newnode->_prev = prev;newnode->_next = pcur;prev->_next = newnode;pcur->_prev = newnode;}//删除指定位置(不能将哨兵位删掉!!iterator erase(iterator pos){assert(pos != end());Node* pcur = pos._node;Node* prev = pcur->_prev;Node* next = pcur->_next;delete pcur;pcur = nullptr;prev->_next = next;next->_prev = prev;return iterator(next);}private:Node* _phead;
};

http://www.zhongyajixie.com/news/5192.html

相关文章:

  • wordpress html5支持张家口网站seo
  • 手机网站可以做商城吗网络违法犯罪举报网站
  • 广州网页设计模板南昌网站优化公司
  • 沧州新华区疫情最新情况优化设计电子版在哪找
  • 天津住房和城乡建设部网站怎么开发一个网站
  • 购买已备案域名网站seo系统
  • 网站建设教程菜鸟教程不受国内限制的搜索引擎
  • 平顶山建设局网站网址搜索
  • wordpress 说说 插件上海牛巨仁seo
  • 网站做影集安全吗注册网址在哪里注册
  • 营销型网站建设哪里济南兴田德润优惠吗app营销策略
  • 网站建设合同 技术合同seo外包一共多少钱
  • 忘记网站后台地址百度竞价排名点击软件
  • 老干部局网站建设seo点石论坛
  • 多张图做网站背景采集站seo课程
  • 成都网站建设冠辰哪家强2023广东最新疫情
  • 网站关键字描述百度怎么免费推广
  • 广州网页设计网站百度广告怎么收费
  • 网络安全行业前景上海aso苹果关键词优化
  • 上海松江建设发展有限公司网站成人营销管理培训班
  • 做网站多长时间网站的推广方法
  • seo网站建设课程全国最新疫情实时状况地图
  • 承德做网站boyun网站seo排名优化
  • python做网站好不好seo怎么做最佳
  • 人才共享网站的建设方案怎么写宁波seo营销
  • 长沙市做网站的网站google官网入口
  • phpcms 图片网站刷网站关键词工具
  • 网站怎样做谷歌推广发布软文网站
  • 房地产门户网站免费的网站域名查询565wcc
  • 做填写信息的超链接用什么网站短视频剪辑培训班速成