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

免费自己建立网站wordpress怎么建立下载

免费自己建立网站,wordpress怎么建立下载,天猫开店流程及费用2022,网店装修图1. list的介绍和使用 1.1 list的介绍 list是可以在常数范围内在任意位置进行插入和删除的序列式容器,并且该容器可以前后双向迭代。list的底层是带头双向循环链表结构,双向链表中每个元素存储在互不相关的独立节点中,在节点中通过指针指向 其…

1. list的介绍和使用

1.1 list的介绍

  1. list是可以在常数范围内在任意位置进行插入和删除的序列式容器,并且该容器可以前后双向迭代。
  2. list的底层是带头双向循环链表结构,双向链表中每个元素存储在互不相关的独立节点中,在节点中通过指针指向 其前一个元素和后一个元素。
  3. list与forward_list非常相似:最主要的不同在于forward_list是单链表,只能朝前迭代,已让其更简单高效。
  4. 与其他的序列式容器相比(array,vector,deque),list通常在任意位置进行插入、移除元素的执行效率 更好。
  5. 与其他序列式容器相比,list和forward_list最大的缺陷是不支持任意位置的随机访问,比如:要访问list 的第6个元素,必须从已知的位置(比如头部或者尾部)迭代到该位置,在这段位置上迭代需要线性的时间 开销;list还需要一些额外的空间,以保存每个节点的相关联信息(对于存储类型较小元素的大list来说这 可能是一个重要的因素)

1.2 list的使用

1.2.1 list的构造

image-20220803141326709

构造函数(constructor)接口说明
list()构造空的list
list (size_type n, const value_type& val = value_type())构造的list中包含n个值为val的元素
list (const list& x)拷贝构造函数
list (InputIterator first, InputIterator last)用[first, last)区间中的元素构造list

1.2.2 list iterator的使用

从实现结构的角度,迭代器分为三类:

  1. 单向。++ 例如:单链表、unordered_map、unordered_set
  2. 双向。++、-- 例如:双链表、map、set、queue
  3. 随机。++、–、+、- 例如:vector、string、deque

image-20220803142943648

函数声明接口说明
begin() + end()返回第一个元素的迭代器 + 返回最后一个元素的下一个位置的迭代器
rbegin() + rend()返回第一个元素的reverse_iterator,即end位置,返回最后一个元素下一个位置的reverse_iterator,即begin()位置

注意:

  1. begin与end为正向迭代器,对迭代器执行++操作,迭代器向后移动
  2. rbegin(end)与rend(begin)为反向迭代器,对迭代器执行++操作,迭代器向前移动

使用举例:

void test_list1()
{list<int> lt;lt.push_back(1);lt.push_back(2);lt.push_back(3);lt.push_back(4);list<int>::iterator it = lt.begin();while (it != lt.end()){cout << *it << " ";it++;}cout << endl;list<int>::reverse_iterator rit = lt.rbegin();while (rit != lt.rend()){cout << *rit << " ";rit++;}cout << endl;
}

运行截图:

image-20220803143547636

1.2.3 list capacity

函数声明接口说明
empty检测list是否为空,是返回true,否则返回false
size返回list中有效节点的个数

1.2.4 list element access

函数声明接口说明
front返回list的第一个节点中值的引用
back返回list的最后一个节点中值的引用

1.2.5 list modifiers

函数声明接口说明
push_front在list首元素前插入值为val的元素
pop_front删除list中第一个元素
push_back在list尾部插入值为val的元素
pop_back删除list中最后一个元素
insert在list position 位置中插入值为val的元素
erase删除list position位置的元素
swap交换两个list中的元素
clear清空list中的有效元素

代码举例:

list<int> lt;
lt.push_back(1);//尾插
lt.push_front(10);//头插
lt.pop_back();//尾删
lt.pop_front();//头删
lt.insert(lt.begin(), 1);//任意位置插入
lt.erase(lt.begin());//任意位置删除
list<int> l1;
list<int> l2;
l1.swap(l2);//交换l1和l2中的元素
lt.clear();

1.2.6 list的sort接口

image-20220803155635107

使用举例:

void test_list2()
{list<int> lt;lt.push_back(1);lt.push_back(6);lt.push_back(7);lt.push_back(4);lt.push_back(8);lt.push_back(10);lt.push_back(9);lt.sort();list<int>::iterator it = lt.begin();while (it != lt.end()){cout << *it << " ";it++;}cout << endl;
}

运行截图:

image-20220803160248577

1.2.7 list的unique

image-20220803185006764

作用:去除重复元素。前提是必须是有序的链表。

使用举例:

void test_list2()
{list<int> lt;lt.push_back(1);lt.push_back(6);lt.push_back(7);lt.push_back(4);lt.push_back(8);lt.push_back(10);lt.push_back(9);lt.push_back(1);lt.push_back(4);lt.push_back(7);lt.push_back(6);lt.push_back(8);lt.sort();lt.unique();list<int>::iterator it = lt.begin();while (it != lt.end()){cout << *it << " ";it++;}cout << endl;
}

运行截图:

image-20220803185151111

1.2.8 list的splice

image-20220803195451035

注意:在将x插入到*this之后,x中的节点都消失了,即都被添加到了*this中。

使用举例:

void test_list3()
{list<int> l1;l1.push_back(1);l1.push_back(2);l1.push_back(3);l1.push_back(4);list<int> l2;l2.push_back(10);l2.push_back(20);l2.push_back(30);l2.push_back(40);auto it = l1.begin();it++;l1.splice(it, l2);cout << "l1:";for (auto e : l1){cout << e << " ";}cout << endl;cout << "l2:";for (auto e : l2){cout << e << " ";}cout << endl;
}

运行截图:

image-20220803200130459

2.list的模拟实现

2.1 list的代码实现

template<class T>
struct list_node
{list_node<T>* _next;list_node<T>* _prev;T _data;list_node(const T& val = T()):_next(nullptr), _prev(nullptr), _data(val){}
};template<class T, class Ref, class Ptr>
struct __list_iterator
{typedef list_node<T> Node;typedef __list_iterator<T, Ref, Ptr> self;Node* _node;__list_iterator(Node* node):_node(node){}Ref operator*(){return _node->_data;}Ptr operator->(){return &(operator*());//return *_node->_data;}self& operator++(){_node = _node->_next;return *this;}self& operator--(){_node = _node->_prev;return *this;}self operator++(int){self tmp(*this);_node = _node->_next;return tmp;}self operator--(int){self tmp(*this);_node = _node->_prev;return tmp;}bool operator!=(const self& it){return _node != it._node;}bool operator==(const self& it){return _node == it._node;}};template<class T>
class mylist
{typedef list_node<T> Node;public:typedef __list_iterator<T, T&, T*> iterator;typedef __list_iterator<T, const T&, const T*> const_iterator;常规写法//mylist(const mylist<T>& lt)//{//	_head = new Node;//	_head->_next = _head;//	_head->_prev = _head;//	for (auto e : lt)//	{//		push_back(e);//	}//}//现代写法mylist(const mylist<T>& lt){empty_init();mylist<T> tmp(lt.begin(), lt.end());swap(tmp);}mylist<T>& operator=(mylist<T> lt){swap(lt);return *this;}template<class InputIterator>mylist(InputIterator first, InputIterator last){empty_init();_head = new Node();_head->_next = _head;_head->_prev = _head;while (first != last){push_back(*first);++first;}}void empty_init(){_head = new Node();_head->_next = _head;_head->_prev = _head;}void swap(mylist<T>& lt){std::swap(_head, lt._head);}iterator begin(){return iterator(_head->_next);}const_iterator begin()const{return const_iterator(_head->_next);}iterator end(){return iterator(_head);}const_iterator end()const{return const_iterator(_head);}mylist(){_head = new Node();_head->_next = _head;_head->_prev = _head;}void push_back(const T& x){//Node* tail = _head->_prev;//Node* newnode = new Node(x);tail newnode _head//tail->_next = newnode;//newnode->_prev = tail;//newnode->_next = _head;//_head->_prev = newnode;insert(end(), x);}void push_front(const T& x){insert(begin(), x);}iterator erase(iterator pos){assert(pos != end());Node* cur = pos._node;Node* prev = cur->_prev;Node* next = cur->_next;//prev nextprev->_next = next;next->_prev = prev;delete cur;return iterator(next);}void pop_back(){erase(--end());}void pop_front(){erase(begin());}//插入在pos位置之前//prev newnode curiterator insert(iterator pos, const T& x){Node* newNode = new Node(x);Node* cur = pos._node;Node* prev = cur->_prev;prev->_next = newNode;newNode->_prev = prev;newNode->_next = cur;cur->_prev = newNode;return iterator(newNode);}~mylist(){clear();delete _head;_head = nullptr;}void clear(){iterator it = begin();while (it != end()){it = erase(it);}}
private:Node* _head;
};

2.2 list 需要注意的点

2.2.1 ->的重载

问:为什么我们要重载->?

答:当mylist存储的自定义类型,例如下面的类型时:

struct AA
{int _a1;int _a2;
}

然后我们想要支持下面的行为(迭代器模拟的是指针,按道理来说应该支持下面的行为):

cout << it->_a1 << it->_a2 << endl;

所以我们需要对这个进行重载:

T* operator->()
{return &(operator*());//operator*()即_data,所以上面等价于&(_node->_data)
}

问:那么it->_a1是如何访问的呢?

答:

it->等价于it.operator->(),其类型为AA*,所以这个地方还是少了一个->,即接下来的访问方式应该是这样的(it.operator->)->_a1,即真正的表达式应该是这样的:it->->_a1

但是编译器为了可读性进行了优化,即it->_a1相当于it->->_a1,优化以后,省略了一个箭头。

http://www.dtcms.com/wzjs/797699.html

相关文章:

  • 正规网站建设费用阿凡达做网站电话
  • 北京网站制作设计推广公司wordpress woo
  • 用子域名可以做网站吗国家建设规范网站
  • 专业的企业智能建站价格便宜陕西省交通集团建设网站
  • 网站建设 财务归类域名查询网站信息
  • 乐清网络问效平台seo研究所
  • dede 中英文网站wordpreSS 搜索优化
  • 湖南企业做网站深圳网站建设世纪前线
  • 网站数据查询wordpress 什么值得买主题
  • 手机网站制作代码夸克搜索网页版
  • 模板网站不利于seo吗延津县建设局网站
  • zencart 网站入侵电脑网站在哪里找
  • 怎样更新网站文章广东建设信息网三库一平台官网
  • 加盟高端网站建设dedecms网站建设合同
  • 番禺微网站建设科技服务公司网站模版
  • 青岛 php 网站建设网络营销推广
  • 搜索网站的软件百度推销广告一年多少钱
  • 网站建设技术大赛试题怎样创建网站桌面快捷方式
  • 鞋行业的网站建设鲜花网站建设项目策 划书
  • 网站建设开源程序中文seo wordpress 插件
  • 路由器上做网站织梦后台如何做网站地图
  • 网站开发就业前景分析wordpress 判断手机版
  • 吴忠市建设网站网站主页设计费用
  • 最新网站网址永久发布搜索推广出价多少合适
  • 东营网站制作手机网站建设的优势
  • h5响应式企业网站源码商丘做网站用什么程序比较好
  • 电子商务网站建设招标书十大网游人气排行榜
  • 合肥官网seo服务东莞网站建设优化推广
  • 烟台定制网站建设报价电子商务网站体系结构有哪些
  • 可以做外链的音乐网站广西网站建设策划