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

注册表怎么做动态网站怎么在平台上做推广

注册表怎么做动态网站,怎么在平台上做推广,湖北可以做网站的公司,网站建设教学廊坊系列文章目录 文章目录 系列文章目录前言list_node<T>&#xff08;节点&#xff09;_list_iterator<T, Ref, Ptr>&#xff08;迭代器&#xff09;成员变量构造函数运算符重载 List<T>&#xff08;链表&#xff09;成员变量构造函数析构函数区间构造函数拷贝构…

系列文章目录


文章目录

  • 系列文章目录
  • 前言
  • list_node<T>(节点)
  • _list_iterator<T, Ref, Ptr>(迭代器)
    • 成员变量
    • 构造函数
    • 运算符重载
  • List<T>(链表)
    • 成员变量
    • 构造函数
    • 析构函数
    • 区间构造函数
    • 拷贝构造
    • 赋值重载
    • Modifiers(修改器)
    • list的迭代器失效


前言

模拟实现list类


STL3.0(SGI版本)

list_node(节点)

//节点类
template<class T>
struct list_node
{//成员变量list_node<T>* _next;list_node<T>* _prev;T _data;//构造函数list_node(cosnt T& x = T()):_next(nullptr), _prev(nullptr),_data(x){}
};

_list_iterator<T, Ref, Ptr>(迭代器)

成员变量

  template<class T, class Ref, class Ptr>struct _list_iterator{//用类来封装node*typedef list_node<T> node;typedef _list__iterator<T, Ref, Ptr> self;node* _node;};

构造函数

//构造函数
_list_iterator(node* n):_node(n)
{}

运算符重载

//Iterator
Ref operator*()
{return _node->_data;
}Ptr operator->()
{//it->_a1 => it->->_a1;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& s)
{return _node != s._node;
}bool operator ==(const self& s)
{return _node == s._node;
}

List(链表)

成员变量

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;private:node* _head;//节点指针
};

构造函数

void empty_init()
{//创建头节点_head = new node;_head->_next = _head;_head->_prev = _head;
}list()
{empty_init();
}

析构函数

//析构函数
~list()
{	clear();//释放头节点delete _head;_head = nullptr;
}

区间构造函数

template <class Iterator>
list(Iterator first, Iterator last)
{empty_init();while (first != last){push_back(*first);++first;}
}

拷贝构造

void swap(list<T>& lt)
{std::swap(_head, lt._head);
}list(const list<T>& lt)
{empty_init();list<T> tmp(lt.begin(), lt.end());swap(tmp);
}

赋值重载

list<T>& operator=(list<T> tmp)
{swap(tmp);return *this;
}

Modifiers(修改器)

void push_back(cosnt T& x)
{insert(end(), x);
}void push_front(const T& x)
{insert(begin(), x);
}void insert(iterator pos, const T& x)
{node* cur = pos._node;node* prev = cur->_prev;node* new_node = new node(x);prev->_next = new_node;new_node->_prev = prev;new_node->_next = cur;cur->_prev = new_node;
}iterator erase(iterator pos)
{assert(pos != end());//头节点不能删node* prev = pos._node->_prev;node* next = pos._node->_next;prev->_next = next;next->_prev = prev;delete pos._node;//删除节点后,返回后一个节点迭代器return iterator(next);
}void clear()
{iterator it = begin();while (it != end()){erase(it++);}
}void pop_back()
{erase(--end);
}
void pop_front()
{erase(begin());
}

list的迭代器失效

void TestListIterator1()
{int array[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };list<int> l(array, array + sizeof(array) / sizeof(array[0]));auto it = l.begin();while (it != l.end()){// erase()函数执行后,it所指向的节点已被删除,因此it无效,在下一次使用it时,必须先给其赋值l.erase(it);++it;}
}
// 改正
void TestListIterator()
{int array[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };list<int> l(array, array + sizeof(array) / sizeof(array[0]));auto it = l.begin();while (it != l.end()){l.erase(it++); // it = l.erase(it);}
}
http://www.hkea.cn/news/161876/

相关文章:

  • win2008sr怎么用iis做网站国外网站加速
  • 合肥++网站建设磐石网站seo
  • 万网主机怎么上传网站如何在百度上投放广告
  • 做网站时如何给文字做超链接全球疫情最新数据消息
  • 四川省住建厅官方网站3分钟搞定网站seo优化外链建设
  • 做网站阳泉巨量千川广告投放平台
  • 温岭哪里有做网站的如何自制网站
  • 知道创于 wordpress搜索引擎优化宝典
  • 乌兰县wap网站建设公司有效获客的六大渠道
  • 微信网站开发教程视频教程百度一下主页官网
  • 网站开发专业前景关键词挖掘排名
  • 网站开发属于什么职位类别seo查询站长工具
  • wordpress postmetaseoul national university
  • 商务网站的主要存在形式杭州百度快照优化公司
  • 个人备案网站做购物网站可以不班级优化大师免费下载电脑版
  • 贸易网站建设互联网广告代理加盟
  • 深圳网站建设网络公司河北关键词排名推广
  • 在工商网上怎么注册公司seo优化博客
  • 免费的小程序怎么赚钱历下区百度seo
  • 河北石家庄最新疫情最新消息优化防疫政策
  • 一站式做网站哪家强新闻小学生摘抄
  • 江西南昌网站建设公司哪家好谷歌google 官网下载
  • 公司网站用什么开发百度指数怎么用
  • 建站主机 wordpress济南网站万词优化
  • 哈尔滨app开发seo自学网官网
  • 网站答辩ppt怎么做全网关键词云在哪里看
  • 网站建设 视频seo关键词词库
  • 网站应用软件设计成都网站建设技术外包
  • 用哪个软件做网站网址查询域名解析
  • 网站安全优化域名停靠浏览器