移动端响应式网站怎么做网站建设行业产业链分析

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

移动端响应式网站怎么做,网站建设行业产业链分析,移动营销做手机网站,指数查询1.序言 STL (Standard Template Library)是C标准库中的一个重要组件#xff0c;提供了许多通用的数据结构和算法。其中#xff0c;STL list是一种带头双向链表容器#xff0c;可以存储任意类型的元素。 list的特点包括#xff1a; 双向性#xff1a;list中的元素可以根据需…1.序言 STL (Standard Template Library)是C标准库中的一个重要组件提供了许多通用的数据结构和算法。其中STL list是一种带头双向链表容器可以存储任意类型的元素。 list的特点包括 双向性list中的元素可以根据需要在前向和后向方向上进行遍历和访问。 动态大小list的大小可以根据需要动态增长和收缩不像数组需要预先定义大小。 高效的插入和删除在list中插入或删除元素的操作非常高效时间复杂度为常数时间。 不支持随机访问由于list的实现是基于链表的所以不支持随机访问只能通过遍历来访问指定位置的元素。 list提供了一系列的成员函数来操作元素包括 push_back()和push_front()分别在list的尾部和头部插入一个元素。 pop_back()和pop_front()分别删除list的尾部和头部的元素。 insert()在指定位置插入一个或多个元素。 erase()删除指定位置的一个或多个元素。 size()返回list中元素的个数。 empty()判断list是否为空。 值得注意的是由于list是双向链表所以在内存上的开销相对较大而且无法通过下标直接访问元素。因此在选择容器时需要根据实际需求进行权衡。 2.list整体结构 templateclass T struct list_node {list_nodeT* _next;list_nodeT* _prev;T _Data;list_node(const T x T()):_next(nullptr), _prev(nullptr), _Data(x){} };templateclass T,class Ref,class Ptr struct __list_iterator {typedef list_nodeT node;typedef __list_iteratorT, Ref, Ptr iterator; node* _node; //··········· };templateclass T class list {typedef list_nodeT node; public:typedef __list_iteratorT, T, T* iterator;typedef __list_iteratorT, const T, const T* const_iterator;//······ private:node* _head;};3.list迭代器 3.1 operator() operator() 返回的是list某节点存储的数据并且返回时要能修改数据所以返回类型是TRef是个模板参数兼顾 T 和 const T 用哪个传那个 。 Ref operator*() {return _node-_Data; }3.2 operator-() operator-() 用于取list存储的数据对象里面的属性也是模拟指针的行为返回数据对象的地址。 Ptr operator-() {return _node-_Data; }需要注意的是如果我们使用这个 - 的运算符重载假设一迭代器对象 it it.operator-()-(某属性) 等价于 it–(某属性) 这里实际上有俩个 - ,为了增加代码的可读性这里进行了特殊处理优化成了一个 - it-(某属性) 。 3.3 operator() 和 operator(int)、operator–() 和 operator–(int) operator()operator–()是前置–返回–后的值operator(int)operator–()是后置–返回前的值–。 iterator operator() {_node _node-_next;return *this; } iterator operator(int) { iterator tmp(*this);_node _node-_next;return tmp; } iterator operator–() {_node _node-_prev;return *this; } iterator operator–(int) {iterator tmp(this);_node _node-_prev;return tmp; }3.4 operator() 和 operator!() bool operator(const iterator it) {return _node it._node; } bool operator!(const iterator it) {return _node ! it._node; }3.5 迭代器完整代码 templateclass T struct list_node { list_nodeT _next; list_nodeT* _prev; T _Data; list_node(const T x T()):_next(nullptr), _prev(nullptr), _Data(x) {} };templateclass T,class Ref,class Ptr struct __list_iterator { typedef list_nodeT node; typedef __list_iteratorT, Ref, Ptr iterator; __list_iterator(node* n):_node(n) {} Ref operator*() {return _node-_Data; } Ptr operator-() {return _node-_Data; }iterator operator() {_node _node-_next;return *this; } iterator operator(int) { iterator tmp(*this);_node _node-_next;return tmp; } iterator operator–() {_node _node-_prev;return *this; } iterator operator–(int) {iterator tmp(this);_node _node-_prev;return tmp; }bool operator(const iterator it) {return _node it._node; } bool operator!(const iterator it) {return _node ! it._node; } node _node; };4.list接口 4.1构造函数 list() {_head new node;_head-_next _head-_prev _head; }~list() {while (end() ! _head){erase(end());}delete _head;_head nullptr; } templateclass Iterator list(Iterator first, Iterator last) {_head new node;_head-_next _head-_prev _head;while (first ! last){push_back(first);first;} }void swap(listT tmp) {std::swap(_head, tmp._head); }list(const listT l) {_head new node;_head-_next _head-_prev _head;listT tmp(l.begin(), l.end());swap(tmp); }4.2 push_back() push_front() pop_back() pop_front() void push_back(const T x) {node tail _head-_prev;node* newnode new node(x);newnode-_prev tail;newnode-_next tail-_next;tail-_next newnode;_head-_prev newnode; }void push_front(const T x) {node* head _head-_next;node* newnode new node(x);newnode-_prev _head;newnode-_next head;_head-_next newnode;head-_prev newnode;} void pop_back() {node* tail _head-_prev;_head-_prev tail-_prev;tail-_prev-_next _head;delete tail; } void pop_front() {node* head _head-_next;_head-_next head-_next;head-_next-_prev _head;delete head; }4.3迭代器 iterator begin() {return iterator(_head-_next); } iterator end() {return iterator(_head); }const_iterator begin() const {return iterator(_head-_next); } const_iterator end() const {return iterator(_head); }4.4 insert() 和 erase() 注意erase的迭代器失效需要更新pos void insert(iterator pos, const T x) {node* cur pos._node;node* newnode new node(x);newnode-_next cur;newnode-_prev cur-_prev;cur-_prev-_next newnode;cur-_prev newnode; }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); }5. list完整代码 #pragma once #includeiostream #includeassert.h using namespace std; namespace zy {templateclass Tstruct list_node{list_nodeT* _next;list_nodeT* _prev;T _Data;list_node(const T x T()):_next(nullptr), _prev(nullptr), _Data(x){}};templateclass T,class Ref,class Ptrstruct __list_iterator{typedef list_nodeT node;typedef list_iteratorT, Ref, Ptr iterator;list_iterator(node* n):_node(n){}Ref operator*(){return _node-_Data;}Ptr operator-(){return _node-_Data;}iterator operator(){_node _node-_next;return *this;}iterator operator(int){ iterator tmp(*this);_node _node-_next;return tmp;}iterator operator–(){_node _node-_prev;return *this;}iterator operator–(int){iterator tmp(this);_node _node-_prev;return tmp;}bool operator(const iterator it){return _node it._node;}bool operator!(const iterator it){return _node ! it._node;}node _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 _head-_prev _head;}~list(){while (end() ! _head){erase(end());}delete _head;_head nullptr;}templateclass Iteratorlist(Iterator first, Iterator last){_head new node;_head-_next _head-_prev _head;while (first ! last){push_back(*first);first;}}void swap(listT tmp){std::swap(_head, tmp._head);}list(const listT l){_head new node;_head-_next _head-_prev _head;listT tmp(l.begin(), l.end());swap(tmp);}listT operator(listT lt){swap(lt);return this;}void push_back(const T x){node tail _head-_prev;node* newnode new node(x);newnode-_prev tail;newnode-_next tail-_next;tail-_next newnode;_head-_prev newnode;}void push_front(const T x){node* head _head-_next;node* newnode new node(x);newnode-_prev _head;newnode-_next head;_head-_next newnode;head-_prev newnode;}void pop_back(){node* tail _head-_prev;_head-_prev tail-_prev;tail-_prev-_next _head;delete tail;}void pop_front(){node* head _head-_next;_head-_next head-_next;head-_next-_prev _head;delete head;}iterator begin(){return iterator(_head-_next);}iterator end(){return iterator(_head);}const_iterator begin() const{return iterator(_head-_next);}const_iterator end() const{return iterator(_head);}void insert(iterator pos, const T x){node* cur pos._node;node* newnode new node(x);newnode-_next cur;newnode-_prev cur-_prev;cur-_prev-_next newnode;cur-_prev newnode;}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);}private:node* _head;}; }