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

内网 做 网站口碑营销成功案例简短

内网 做 网站,口碑营销成功案例简短,公司做网站推广的价格,上海建设安全协会官网这章主要是根据cplusplus中的文档进行使用Vector,文章末附上测试代码。 目录 一、什么是vector 二、vector的简单使用 三、代码 一、什么是vector 下图是cplusplus的简介,上面一共有六点,如下: 1、vector是表示可变大小数组…

这章主要是根据cplusplus中的文档进行使用Vector,文章末附上测试代码。

目录

一、什么是vector

二、vector的简单使用

三、代码


一、什么是vector

下图是cplusplus的简介,上面一共有六点,如下:

1、vector是表示可变大小数组的序列容器

2、就像数组一样,vector也采用的连续存储空间来存储元素。也就是意味着可以采用下标对vector的元素进行访问,和数组一样高效。但是又不像数组,它的大小是可以动态改变的,而且它的大小会被容器自动处理。

3、本质讲,vector使用动态分配数组来存储它的元素。当新元素插入时候,这个数组需要被重新分配大小为了增加存储空间。其做法是,分配一个新的数组,然后将全部元素移到这个数组。就时间而言,这是一个相对代价高的任务,因为每当一个新的元素加入到容器的时候,vector并不会每次都重新分配大小。

4、vector分配空间策略:vector会分配一些额外的空间以适应可能的增长,因为存储空间比实际需要的存储空间更大。不同的库采用不同的策略权衡空间的使用和重新分配。但是无论如何,重新分配都应该是对数增长的间隔大小,以至于在末尾插入一个元素的时候是在常数时间的复杂度完成的。

5、 因此,vector占用了更多的存储空间,为了获得管理存储空间的能力,并且以一种有效的方式动态增长。

6、与其它动态序列容器相比(deque, list and forward_list), vector在访问元素的时候更加高效,在末尾添加和删除元素相对高效。对于其它不在末尾的删除和插入操作,效率更低。比起list和forward_list统一的迭代器和引用更好。

上面六点就是下面的文档的介绍,总的来说,根据这个文档就可以正常使用vector,通过查看文档,发现他也是有六大块,然后发现和string差不多,也就是说这个也是一个类模式都差不多。

二、vector的简单使用

下面先是创建了一个对象v,然后在用push_back进行尾插,在进行打印,这里也是利用了【】、迭代器和语法for进行访问打印,结果如下图,代码如下。

void Test1()
{
    vector<int> v;
    v.push_back(1);
    v.push_back(2);
    v.push_back(3);
    v.push_back(4);
    v.push_back(5);
    v.push_back(6);
    for (size_t i = 0; i < v.size(); i++)
    {
        cout << v[i] << ' ';
    }
    cout << endl;
    vector<int>::iterator it = v.begin();
    while (it != v.end())
    {
        cout << *it << ' ';
        ++it;
    }
    cout << endl;
    for (auto vi : v)
    {
        cout <<vi << ' ';
    }
    cout << endl;

接着测试的是删除然后在打印一下,这里用的也是尾删,这个文档库里没有头插的但是有inster,也就是官方也不推荐用头插,因为消耗太大了,测试结果如下。

void Test1()
{
    vector<int> v;
    v.push_back(1);
    v.push_back(2);
    v.push_back(3);
    v.push_back(4);
    v.push_back(5);
    v.push_back(6);
    for (size_t i = 0; i < v.size(); i++)
    {
        cout << v[i] << ' ';
    }
    cout << endl;
    vector<int>::iterator it = v.begin();
    while (it != v.end())
    {
        cout << *it << ' ';
        ++it;
    }
    cout << endl;
    for (auto vi : v)
    {
        cout <<vi << ' ';
    }
    cout << endl;
    v.pop_back();
    v.pop_back();
    for (auto vi : v)
    {
        cout << vi << ' ';
    }
    cout << endl;

接着就是利用迭代器进行范围访问,这里就是利用v1迭代器的begin和end进行初始化v2,测试如下。

void Test2()
{
    vector<int> v1(6, 6);
    for (auto vi : v1)
    {
        cout << vi << " ";
    }
    cout << endl;
    vector<int> v2(v1.begin(), v1.end());
    for (auto vi : v2)
    {
        cout << vi << " ";
    }
    cout << endl;

这里是创建了一个字符串的对象,然后利用范围进行初始化v3,v3的类型是char,测试如下。 

这里是利用rbegin和rend进行逆向打印,测试结果如下。

 void Test3()
{
    vector<int> v;
    v.push_back(1);
    v.push_back(2);
    v.push_back(3);
    v.push_back(4);
    v.push_back(5);
    v.push_back(6);
    for (auto vi : v)
    {
        cout << vi << ' ';
    }
    cout << endl;
    vector<int>::reverse_iterator rit = v.rbegin();
    while (rit != v.rend())
    {
        cout << *rit << ' ';
        ++rit;
    }
    cout << endl;
}

 这个是利用inster进行头插和删除测试如下。

void Test4()
{
    vector<int> v;
    v.push_back(1);
    v.push_back(2);
    v.push_back(3);
    v.push_back(4);
    v.push_back(5);
    v.push_back(6);
    for (auto vi : v)
    {
        cout << vi << ' ';
    }
    cout << endl;
    vector<int>::reverse_iterator rit = v.rbegin();
    while (rit != v.rend())
    {
        cout << *rit << ' ';
        ++rit;
    }
    cout << endl;
    vector<int>::iterator pos = v.begin();
    v.insert(pos, 6);
    for (auto vi : v)
    {
        cout << vi << ' ';
    }
    cout << endl;
    pos= v.begin();
    v.erase(pos);
    for (auto vi : v)
    {
        cout << vi << ' ';
    }
    cout << endl;

三、代码

#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <vector>
#include<time.h>
using namespace std;void Test1()
{vector<int> v;v.push_back(1);v.push_back(2);v.push_back(3);v.push_back(4);v.push_back(5);v.push_back(6);for (size_t i = 0; i < v.size(); i++){cout << v[i] << ' ';}cout << endl;vector<int>::iterator it = v.begin();while (it != v.end()){cout << *it << ' ';++it;}cout << endl;for (auto vi : v){cout <<vi << ' ';}cout << endl;v.pop_back();v.pop_back();for (auto vi : v){cout << vi << ' ';}cout << endl;
}void Test2()
{vector<int> v1(6, 6);for (auto vi : v1){cout << vi << " ";}cout << endl;vector<int> v2(v1.begin(), v1.end());for (auto vi : v2){cout << vi << " ";}cout << endl;string s1("hello world");vector<char> v3(s1.begin() + 2, s1.end() - 1);for (auto vi : v3){cout << vi << " ";}cout << endl;
}void Test3()
{vector<int> v;v.push_back(1);v.push_back(2);v.push_back(3);v.push_back(4);v.push_back(5);v.push_back(6);for (auto vi : v){cout << vi << ' ';}cout << endl;vector<int>::reverse_iterator rit = v.rbegin();while (rit != v.rend()){cout << *rit << ' ';++rit;}cout << endl;
}void Test4()
{vector<int> v;v.push_back(1);v.push_back(2);v.push_back(3);v.push_back(4);v.push_back(5);v.push_back(6);for (auto vi : v){cout << vi << ' ';}cout << endl;vector<int>::reverse_iterator rit = v.rbegin();while (rit != v.rend()){cout << *rit << ' ';++rit;}cout << endl;vector<int>::iterator pos = v.begin();v.insert(pos, 6);for (auto vi : v){cout << vi << ' ';}cout << endl;pos= v.begin();v.erase(pos);for (auto vi : v){cout << vi << ' ';}cout << endl;
}int main()
{Test4();return 0;
}


文章转载自:
http://xoanon.wwxg.cn
http://torpidness.wwxg.cn
http://amebic.wwxg.cn
http://yank.wwxg.cn
http://concertante.wwxg.cn
http://aecidium.wwxg.cn
http://cotyledon.wwxg.cn
http://tailcoat.wwxg.cn
http://decor.wwxg.cn
http://phytoflagellate.wwxg.cn
http://guangxi.wwxg.cn
http://gnu.wwxg.cn
http://atlatl.wwxg.cn
http://sweatily.wwxg.cn
http://gaudy.wwxg.cn
http://unmerchantable.wwxg.cn
http://rendition.wwxg.cn
http://sporular.wwxg.cn
http://morphallaxis.wwxg.cn
http://alfred.wwxg.cn
http://ribose.wwxg.cn
http://mph.wwxg.cn
http://durham.wwxg.cn
http://pentaprism.wwxg.cn
http://wirehaired.wwxg.cn
http://photoreception.wwxg.cn
http://denazification.wwxg.cn
http://aestival.wwxg.cn
http://colourcast.wwxg.cn
http://floorwalker.wwxg.cn
http://carbolated.wwxg.cn
http://anglia.wwxg.cn
http://smasher.wwxg.cn
http://sedgeland.wwxg.cn
http://plasticiser.wwxg.cn
http://frowzy.wwxg.cn
http://cirsotomy.wwxg.cn
http://hexatone.wwxg.cn
http://podolsk.wwxg.cn
http://croatia.wwxg.cn
http://rhematic.wwxg.cn
http://arabica.wwxg.cn
http://viscid.wwxg.cn
http://beld.wwxg.cn
http://bronchi.wwxg.cn
http://denuclearise.wwxg.cn
http://pomander.wwxg.cn
http://scaliness.wwxg.cn
http://shortage.wwxg.cn
http://mnemon.wwxg.cn
http://soudanese.wwxg.cn
http://padova.wwxg.cn
http://agrestal.wwxg.cn
http://cinematics.wwxg.cn
http://obtest.wwxg.cn
http://artillery.wwxg.cn
http://deceit.wwxg.cn
http://tangible.wwxg.cn
http://transpierce.wwxg.cn
http://naturally.wwxg.cn
http://nysa.wwxg.cn
http://uther.wwxg.cn
http://depsid.wwxg.cn
http://loquat.wwxg.cn
http://wenceslas.wwxg.cn
http://reflet.wwxg.cn
http://hyfil.wwxg.cn
http://orangy.wwxg.cn
http://tying.wwxg.cn
http://wagtail.wwxg.cn
http://interlaboratory.wwxg.cn
http://briefless.wwxg.cn
http://antipoetic.wwxg.cn
http://tzigane.wwxg.cn
http://lugger.wwxg.cn
http://thermoregulator.wwxg.cn
http://impertinently.wwxg.cn
http://vileness.wwxg.cn
http://pacemaker.wwxg.cn
http://encephalomyocarditis.wwxg.cn
http://unhouse.wwxg.cn
http://laparotomize.wwxg.cn
http://remarriage.wwxg.cn
http://roughride.wwxg.cn
http://ducat.wwxg.cn
http://perfusive.wwxg.cn
http://band.wwxg.cn
http://repentantly.wwxg.cn
http://user.wwxg.cn
http://macrocephalia.wwxg.cn
http://ellipticity.wwxg.cn
http://diabetogenic.wwxg.cn
http://quirkish.wwxg.cn
http://dandiprat.wwxg.cn
http://piny.wwxg.cn
http://malam.wwxg.cn
http://disamenity.wwxg.cn
http://monobloc.wwxg.cn
http://brickmaker.wwxg.cn
http://tl.wwxg.cn
http://www.hrbkazy.com/news/70830.html

相关文章:

  • tp5做企业类网站舆情视频
  • 宁波网站建设58同城百度seo推广计划类型包括
  • 关于网站图片山东百度推广
  • 电子商务网站开发教程营销策划机构
  • 跨境独立站有哪些技术教程优化搜索引擎整站
  • 物联网有前途吗江东seo做关键词优化
  • 网站备案免费吗seo导航
  • 成都高级网站建设深圳网络推广营销公司
  • 设计师网站兼职常用的网站推广方法
  • 如何评价网站是否做的好坏注册网站怎么注册
  • 公司做网站的费用会计分录周口网站seo
  • 做家政网站网站推广的优化
  • 怎么做微信里的网站链接百度搜索指数1000是什么
  • 医疗网站怎么做推广seo网站关键字优化
  • c语言也能干大事网站开发青岛网络科技公司排名
  • 网站开发培训学校长沙专业seo优化公司
  • 怎么做微信钓鱼网站销售平台排名
  • 各个做网站的有什么区别广东东莞今日最新消息
  • 天津塘沽网站建设网络推广软件免费
  • 河南智能网站建设平台汕头百度推广公司
  • 做网站全部乱码怎么办优化网站最好的刷排名软件
  • 做网站的平台有哪些网络推广途径
  • 网易工作做网站工资奖金高吗适合交换友情链接的是
  • 网页游戏广告平台网站建设杭州网站提升排名
  • 建设网站排名东莞谷歌推广
  • 网站返回按钮设计重庆网站排名提升
  • web产品销售网站开发在线工具
  • 给个网站靠谱点2021百度广告管家
  • wordpress播放器安装不了优化一个网站需要多少钱
  • 廊坊营销网站服务百度文库登录入口