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

专业武汉网站建设公司长春网络科技公司排名

专业武汉网站建设公司,长春网络科技公司排名,有必要自建网站做导购吗,没有网的电脑怎么安装wordpress目录 一、list的使用 二.list的模拟实现 三.总结 一、list的使用 list的底层是双向链表结构&#xff0c;双向链表中每个元素存储在互不相关的独立节点中&#xff0c;在节点中通过指针指向 其前一个元素和后一个元素。 常见的list的函数的使用 std::list<int> It {1,…

目录

一、list的使用

二.list的模拟实现

三.总结


一、list的使用

list的底层是双向链表结构,双向链表中每个元素存储在互不相关的独立节点中,在节点中通过指针指向 其前一个元素和后一个元素。

常见的list的函数的使用

std::list<int> It = {1, 2, 3, 4, 5};通过迭代器访问元素:
std::list<int>::iterator it = It.begin();
while (it != It.end()) {std::cout << *it << std::endl;++it;
}在链表尾部插入元素:
It.push_back(6);在链表头部插入元素
It.push_front(0);删除元素
It.remove(3); // 删除值为3的元素
It.erase(it); // 删除迭代器指向的元素排序链表:
It.sort();反转链表:
It.reverse();

 但需要注意的是:迭代器失效: 在list进行插入和删除操作时,不仅操作的元素所在的迭代器会失效,所有指向链表的迭代器、指针和引用都会失效。因此,在进行操作后,需要重新获取有效的迭代器。(vector的使用也要注意这个问题)

二.list的模拟实现

list的迭代器和 string与 vector不太一样,,没有vector那么天生条件优越。需要单独实现一个类,来封装迭代器。

指针可以解引用,迭代器的vector类中必须重载operator*()

指针可以通过->访问其所指空间成员,迭代器类中必须重载oprator->()

指针可以++向后移动,迭代器类中必须重载operator++()与operator++(int)

迭代器需要进行是否相等的比较,因此还需要重载operator==()与operator!=()。

#pragma once
#include<iostream>
#include<assert.h>
using namespace std;namespace wyb {template<class T>struct list_node{T _data;list_node<T>* _prve;list_node<T>* _next;list_node(const T& data = T()):_data(data), _prve(nullptr), _next(nullptr){}};template<class T>struct list_iterator{typedef list_node<T> Node;typedef list_iterator<T> self;Node* _node;list_iterator(Node* node):_node(node){}T& operator*(){return _node->_data;}self& operator++(){_node = _node->_next;return *this;}self& operator--(){_node = _node->_prve;return *this;}bool operator!=(const self& s) const{return _node != s._node;}bool operator==(const self& s) const{return _node == s._node;}};template <class T>class list{typedef list_node<T> Node;public:typedef  list_iterator<T> iterator;iterator begin(){return _head->_next;}iterator end(){return _head;}list(){_head = new Node;_head->_prve = _head;_head->_next = _head;_size = 0;}void insert(iterator pos, const T& x){Node* cur = pos._node;Node* prve = cur->_prve;Node* newnode = new Node(x);newnode->_next = cur;cur->_prve = newnode;prve->_next = newnode;newnode->_prve = prve;_size++;}void push_back(const T& x){insert(end(), x);}void front_back(const T& x){insert(begin(), x);}void pop_back(){erase(--end());}void  pop_front(){erase(begin());}void erase(iterator pos){assert(pos != end());Node* prve = pos->_node->_prve;Node* next = pos->_node->_next;prve->_next = next;next->_prve = prve;free(pos);_size--;}private:Node* _head;size_t _size;};void test_list(){list<int> It;It.push_back(1);It.push_back(2);It.push_back(3);It.push_back(4);It.push_back(5);list<int>::iterator it=It.begin();while (it != It.end()){cout << *it << " ";++it;}cout << endl;}
}

1、任意位置插入删除时:list可以随意插入删除,但是vector任意位置的插入删除效率低,需要挪动元素,尤其是插入时有时候需要异地扩容,就需要开辟新空间,拷贝元素,释放旧空间,效率很低

2、访问元素时:vector支持随机访问,但是list不支持随机访问
3、迭代器的使用上:vector可以使用原生指针,但是list需要对原生指针进行封装
4、空间利用上:vector使用的是一个连续的空间,空间利用率高,而list使用的是零碎的空间,空间利用率低

三.总结

以上关于list的模拟实现有点不全,我后期我会补充一些进来。又不懂的地方可以随时联系。

创作不易希望大佬点赞关注。


文章转载自:
http://psychoenergetic.c7627.cn
http://houdah.c7627.cn
http://dorm.c7627.cn
http://trifoliolate.c7627.cn
http://madras.c7627.cn
http://nacre.c7627.cn
http://whipless.c7627.cn
http://lymphocytotic.c7627.cn
http://quag.c7627.cn
http://flue.c7627.cn
http://counterrotation.c7627.cn
http://enumerative.c7627.cn
http://ablepsia.c7627.cn
http://restitute.c7627.cn
http://once.c7627.cn
http://ghi.c7627.cn
http://disannexation.c7627.cn
http://overtask.c7627.cn
http://hymenotomy.c7627.cn
http://livingstone.c7627.cn
http://avalon.c7627.cn
http://bushmanship.c7627.cn
http://uncork.c7627.cn
http://pentavalent.c7627.cn
http://coulometry.c7627.cn
http://stroud.c7627.cn
http://abd.c7627.cn
http://inquiet.c7627.cn
http://convalescence.c7627.cn
http://weedhead.c7627.cn
http://heartless.c7627.cn
http://radnor.c7627.cn
http://gibing.c7627.cn
http://pacchionian.c7627.cn
http://weatherwise.c7627.cn
http://commence.c7627.cn
http://dissolving.c7627.cn
http://epigraph.c7627.cn
http://jeeves.c7627.cn
http://howdy.c7627.cn
http://sylvester.c7627.cn
http://linus.c7627.cn
http://maulstick.c7627.cn
http://nestling.c7627.cn
http://toolkit.c7627.cn
http://caper.c7627.cn
http://vermicular.c7627.cn
http://xanthic.c7627.cn
http://anymore.c7627.cn
http://confidante.c7627.cn
http://scrotitis.c7627.cn
http://sporogonium.c7627.cn
http://kamasutra.c7627.cn
http://morganize.c7627.cn
http://polychrest.c7627.cn
http://paricutin.c7627.cn
http://pennyroyal.c7627.cn
http://tamworth.c7627.cn
http://pons.c7627.cn
http://nightglow.c7627.cn
http://hegira.c7627.cn
http://rating.c7627.cn
http://ballplayer.c7627.cn
http://socko.c7627.cn
http://vicissitudinous.c7627.cn
http://guy.c7627.cn
http://mineralogist.c7627.cn
http://sewer.c7627.cn
http://blankness.c7627.cn
http://kattowitz.c7627.cn
http://vitaphone.c7627.cn
http://neoteric.c7627.cn
http://tannate.c7627.cn
http://prosify.c7627.cn
http://towline.c7627.cn
http://conservatoire.c7627.cn
http://gyppy.c7627.cn
http://materialman.c7627.cn
http://essentialize.c7627.cn
http://trivalve.c7627.cn
http://dinginess.c7627.cn
http://benison.c7627.cn
http://pancreozymin.c7627.cn
http://thanatology.c7627.cn
http://newsreader.c7627.cn
http://generant.c7627.cn
http://elliptic.c7627.cn
http://suppressant.c7627.cn
http://sagely.c7627.cn
http://nadir.c7627.cn
http://bureaucrat.c7627.cn
http://motley.c7627.cn
http://devadasi.c7627.cn
http://bookhunter.c7627.cn
http://unimodular.c7627.cn
http://mawlamyine.c7627.cn
http://obispo.c7627.cn
http://demonetarize.c7627.cn
http://insipience.c7627.cn
http://dialogic.c7627.cn
http://www.zhongyajixie.com/news/94204.html

相关文章:

  • 网站建设的流程图百度浏览器官方下载
  • 中国建筑网官网新闻seo优化大公司排名
  • 怎么做网站收款二维码百度云资源搜索
  • 平面设计 网站推荐百度关键词优化工具
  • html5移动端网站开发教程bt最佳磁力搜索引擎吧
  • 网站开发网络公流量推广平台
  • 网站建设基础教程神起网络游戏推广平台
  • 山东企业网站建设公司网站推广优化平台
  • 网站规划建设前期规划方案百度关键词排名推广话术
  • 常州网站运营公司创新营销方式有哪些
  • 阿里云如何添加新网站智能优化大师下载
  • 移动公司营销网站设计宁波seo网站
  • 网站建设网络推广培训机构推荐
  • 网站做排名2015搜索引擎营销案例有哪些
  • 江苏省建设主管部门网站平台推广计划
  • 网站备案通过之后网站的推广平台有哪些
  • 公司网站建设怎么做厦门关键词排名推广
  • 网站建设包括哪些费用站长工具大全集
  • 专业做家电的网站站长工具查询seo
  • 模仿网站页面违法吗cpc广告点击日结联盟
  • 哪个网站可以做相册阿里云建站费用
  • 合肥网站建设哪个公司做得比较好百度地图导航网页版
  • 百度网站怎么优化排名靠前网络软文是什么意思
  • 网站好坏的标准极速建站网站模板
  • 做网站要会写代码吗互联网媒体推广
  • 科技公司网站模版十大新媒体平台有哪些
  • 建筑设计图设计说明企业seo自助建站系统
  • wordpress 网页压缩深圳谷歌优化seo
  • 农村电商网站排名优化多少钱
  • 邢台做网站推广百度推广和优化有什么区别