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

企业每年向工商网站做申报页面设计漂亮的网站

企业每年向工商网站做申报,页面设计漂亮的网站,网站运维工作内容,教你做面膜v官方网站C STL(标准模板库)中的容器是一组通用的、可复用的数据结构,用于存储和管理不同类型的数据。 目录 零. 简介: 一 . vector(动态数组) 二. list(双向链表) 三. deque&#xff08…

C++ STL(标准模板库)中的容器是一组通用的、可复用的数据结构,用于存储和管理不同类型的数据。

目录

零. 简介:

一 . vector(动态数组)

二. list(双向链表)

三. deque(双端队列)

四. set(集合)

五. map(映射)


零. 简介


STL 容器提供了一系列预定义的类,如 vector(动态数组)、list(双向链表)、deque(双端队列)、set(集合)、map(映射)等。

意义和作用

  1. 提高编程效率:无需自己实现常见的数据结构。
  2. 代码简洁:使用统一的接口和操作方式。
  3. 灵活性:适应不同的需求和数据类型。
  4. 可扩展性:易于添加新的容器或扩展现有容器的功能。
  5. 性能优化:经过精心设计和优化。
  6. 类型安全:在编译时进行类型检查。
  7. 代码可维护性:减少重复代码,提高代码的可读性和可维护性。

例如,使用 vector 可以方便地管理动态数组,而不需要自己手动实现动态内存分配和元素添加、删除等操作。

一 . vector(动态数组)

vector 是 C++ STL 中的一种动态数组容器。它具有以下特点和优势:

  1. 动态调整大小:可以根据需要自动调整存储空间。
  2. 高效的随机访问:支持通过索引进行快速访问。
  3. 易于使用:提供了丰富的接口和操作方法。
  4. 自动内存管理:无需手动处理内存分配和释放。

有以下常用的 API:

  • push_back():在数组末尾添加元素。
  • pop_back():删除数组末尾的元素。
  • at():通过索引访问元素,提供边界检查。
  • [] 操作符:通过索引访问元素。
  • size():获取数组中元素的数量。
  • empty():判断数组是否为空。
  • begin():获取数组的起始迭代器。
  • end():获取数组的末尾迭代器。
  • clear():清空数组中的所有元素。
  • insert():在指定位置插入元素。
  • erase():删除指定元素或指定范围的元素。

以下是一个使用 vector 的示例代码:

#include <vector>
#include <iostream>int main() {std::vector<int> numbers;// 向 vector 中添加元素numbers.push_back(1);numbers.push_back(2);numbers.push_back(3);// 输出 vector 中的元素for (int num : numbers) {std::cout << num << " ";}std::cout << std::endl;return 0;
}

前面的文章有更详细的介绍:http://t.csdnimg.cn/QMcDR

二. list(双向链表)

list 是 C++ STL 中的双向链表容器.

它具有以下常用的 API:

  • push_back():在链表末尾添加元素。
  • push_front():在链表开头添加元素。
  • insert():在指定位置插入元素。
  • erase():删除指定元素或指定范围的元素。
  • clear():清空链表中的所有元素。
  • size():获取链表中元素的数量。
  • empty():判断链表是否为空。
  • front():获取链表开头的元素。
  • back():获取链表末尾的元素。
  • begin():获取链表的起始迭代器。
  • end():获取链表的末尾迭代器。

以下是一个使用 list 的示例代码:

#include <list>
#include <iostream>int main() {std::list<int> numbers;// 在链表末尾添加元素numbers.push_back(1);numbers.push_back(2);numbers.push_back(3);// 在链表开头添加元素numbers.push_front(0);// 输出链表中的元素for (int num : numbers) {std::cout << num << " ";}std::cout << std::endl;return 0;
}

三. deque(双端队列)

deque 是一种可以在两端高效地进行插入和删除操作的容器。
意义和作用

  1. 高效的两端操作:可以在队列的两端快速添加和删除元素。
  2. 动态调整大小:自动根据需要调整内存。
  3. 支持随机访问:像数组一样,可以通过索引访问元素。
  4. 通用数据结构:适用于多种场景。
  5. 提高代码效率和可维护性:提供了简洁、高效的接口。

例如,可以使用 deque 来实现一个队列或栈的功能。

常用 API 包括:

  • push_back():在队列尾部添加元素。
  • push_front():在队列头部添加元素。
  • pop_back():从队列尾部删除元素。
  • pop_front():从队列头部删除元素。
  • insert():在指定位置插入元素。
  • erase():删除指定元素或指定范围的元素。
  • clear():清空队列中的所有元素。
  • size():获取队列中元素的数量。
  • empty():判断队列是否为空。
  • begin():获取队列的起始迭代器。
  • end():获取队列的末尾迭代器。

下面是一个简单的 deque 使用示例代码:

#include <deque>
#include <iostream>int main() {std::deque<int> numbers;numbers.push_back(1); //向最后面插入数据   1numbers.push_front(2);//向最钱面插入数据   2, 1numbers.push_back(3); //向最后面插入数据   2, 1,3numbers.push_front(4);//向最钱面插入数据   4, 2, 1,3std::cout << "Front: " << numbers.front() << std::endl;std::cout << "Back: " << numbers.back() << std::endl;return 0;
}

四. set(集合)

set 是一种无序且不允许重复元素的容器。

意义和作用

  1. 自动去重:无需手动处理重复元素。
  2. 快速查找:提供高效的元素查找操作。
  3. 无序存储:元素的顺序是随机的。
  4. 键值对操作:常用于存储键值。

常用的 API 包括:

  • insert():插入元素。
  • find():查找元素。
  • erase():删除元素。
  • size():获取元素数量。
  • empty():判断是否为空。

下面是一个简单的示例代码:

#include <set>
#include <iostream>int main() {std::set<int> numbers = { 1, 2, 3, 4, 5 };numbers.insert(3);//插入已有数据 3numbers.insert(6); //插入未有数据//循环打印for (std::set<int>::iterator i = numbers.begin(); i != numbers.end(); ++i){std::cout << *i << std::endl;}// 查找元素if (numbers.find(3) != numbers.end()) {std::cout << "Element found" << std::endl;}else {std::cout << "Element not found" << std::endl;}return 0;
}

五. map(映射)

map(映射)是一种关联容器,它将键(key)和值(value)进行关联。 是一种无序容器,其中键必须是唯一的。

意义和作用

  1. 提供了一种键值对的存储方式。
  2. 快速的键值查找。
  3. 自动根据键进行排序。

常用 API

  • insert():插入键值对。
  • find():根据键查找对应的值。
  • erase():删除键值对。
  • size():获取映射中键值对的数量。
  • empty():判断映射是否为空。

下面是一个简单的示例代码:

#include <map>
#include <iostream>int main() {std::map<std::string, int> grades;grades["a"] = 1;grades["b"] = 2;grades["c"] = 3;// 根据键查找值int aliceGrade = grades["a"];std::cout << "a: " << aliceGrade << std::endl;return 0;
}

扩展:

可以用来做观察者模式;

观察者模式是一种设计模式,它定义了对象之间的一种一对多的依赖关系,当一个对象的状态发生改变时,所有依赖于它的对象都会得到通知并自动更新。

在 C++ 中,可以使用观察者模式来实现 map 的变化通知。下面是一个简单的示例代码:

#include <iostream>
#include <map>
#include <string>
#include <vector>class Observer {
public:virtual void update() = 0;
};class Subject {
private:std::map<std::string, int> data;std::vector<Observer*> observers;public:void addObserver(Observer* observer) {observers.push_back(observer);}void removeObserver(Observer* observer) {auto it = std::find(observers.begin(), observers.end(), observer);if (it != observers.end()) {observers.erase(it);}}void updateObservers() {for (Observer* observer : observers) {observer->update();}}void setKeyValue(const std::string& key, int value) {data[key] = value;updateObservers();}int getValue(const std::string& key) {return data[key];}
};class DisplayObserver1 : public Observer {
public:void update() override {std::cout << "Data changed1" << std::endl;}
};class DisplayObserver2 : public Observer {
public:void update() override {std::cout << "Data changed2" << std::endl;}
};int main() {Subject subject;DisplayObserver1 observer1;subject.addObserver(&observer1);DisplayObserver2 observer2;subject.addObserver(&observer2);subject.setKeyValue("key1", 10);return 0;
}


文章转载自:
http://dinncoimmigrant.bkqw.cn
http://dinncoumtata.bkqw.cn
http://dinncounhuman.bkqw.cn
http://dinncosmokables.bkqw.cn
http://dinncoolaf.bkqw.cn
http://dinncobefall.bkqw.cn
http://dinncojestbook.bkqw.cn
http://dinncoexornation.bkqw.cn
http://dinncofloodlight.bkqw.cn
http://dinncorajput.bkqw.cn
http://dinncoinhumanity.bkqw.cn
http://dinncoteleconsultation.bkqw.cn
http://dinncobounteously.bkqw.cn
http://dinncozoology.bkqw.cn
http://dinncohedgehog.bkqw.cn
http://dinncoafterpains.bkqw.cn
http://dinncounevoked.bkqw.cn
http://dinncobrimmy.bkqw.cn
http://dinncoparachute.bkqw.cn
http://dinncoweser.bkqw.cn
http://dinncoecdysterone.bkqw.cn
http://dinncoadiaphorist.bkqw.cn
http://dinncodisgusting.bkqw.cn
http://dinncoclemency.bkqw.cn
http://dinncoxiangtan.bkqw.cn
http://dinncotherewith.bkqw.cn
http://dinncodinotherium.bkqw.cn
http://dinncopopple.bkqw.cn
http://dinncofanciless.bkqw.cn
http://dinncogranita.bkqw.cn
http://dinncoinfrequently.bkqw.cn
http://dinncocha.bkqw.cn
http://dinncowindow.bkqw.cn
http://dinncoelicitation.bkqw.cn
http://dinncohoofpick.bkqw.cn
http://dinncobiostrategy.bkqw.cn
http://dinncoyesman.bkqw.cn
http://dinncomarginate.bkqw.cn
http://dinncoglycogenesis.bkqw.cn
http://dinncoghastful.bkqw.cn
http://dinncogangetic.bkqw.cn
http://dinncocorresponding.bkqw.cn
http://dinncophagomania.bkqw.cn
http://dinncomonophobia.bkqw.cn
http://dinncoodalisk.bkqw.cn
http://dinncomutilator.bkqw.cn
http://dinncodrab.bkqw.cn
http://dinncoquantitative.bkqw.cn
http://dinncocreepily.bkqw.cn
http://dinncoaccidented.bkqw.cn
http://dinncoconnected.bkqw.cn
http://dinncograpeshot.bkqw.cn
http://dinncobutterscotch.bkqw.cn
http://dinncosoreness.bkqw.cn
http://dinncoclart.bkqw.cn
http://dinncopolychromasia.bkqw.cn
http://dinncounsf.bkqw.cn
http://dinncoassassinator.bkqw.cn
http://dinncoinactivity.bkqw.cn
http://dinncohireable.bkqw.cn
http://dinncoproline.bkqw.cn
http://dinncomisanthropist.bkqw.cn
http://dinncospare.bkqw.cn
http://dinncoillative.bkqw.cn
http://dinncosteaminess.bkqw.cn
http://dinncotoggle.bkqw.cn
http://dinncothankfulness.bkqw.cn
http://dinncointerpolatory.bkqw.cn
http://dinncospate.bkqw.cn
http://dinncoassailant.bkqw.cn
http://dinncognawn.bkqw.cn
http://dinncoavalanche.bkqw.cn
http://dinncogrenadine.bkqw.cn
http://dinncohabitus.bkqw.cn
http://dinncolaurette.bkqw.cn
http://dinncocouth.bkqw.cn
http://dinncomanganous.bkqw.cn
http://dinncoelectrotactic.bkqw.cn
http://dinncoib.bkqw.cn
http://dinncorevealing.bkqw.cn
http://dinncoropewalker.bkqw.cn
http://dinncostoreship.bkqw.cn
http://dinncopopsicle.bkqw.cn
http://dinncomargarita.bkqw.cn
http://dinncoedo.bkqw.cn
http://dinncohominization.bkqw.cn
http://dinncotranslucency.bkqw.cn
http://dinncohominid.bkqw.cn
http://dinncowhangdoodle.bkqw.cn
http://dinncowazir.bkqw.cn
http://dinncogriselda.bkqw.cn
http://dinncouncooked.bkqw.cn
http://dinncoprofessoriate.bkqw.cn
http://dinncothreadlike.bkqw.cn
http://dinncoboong.bkqw.cn
http://dinncounharmful.bkqw.cn
http://dinncoswarthily.bkqw.cn
http://dinncoprotonema.bkqw.cn
http://dinncoanglophile.bkqw.cn
http://dinncoframboise.bkqw.cn
http://www.dinnco.com/news/97562.html

相关文章:

  • 创建网站制作首页新疆头条今日头条新闻
  • wordpress 手机站seo数据
  • 湖南网站建设公司 要上磐石网络百度小说排行榜总榜
  • mac 网站开发 软件杭州营销策划公司排名
  • 福田网站建设设计公司哪家好游戏推广员是做什么的
  • 网站首页三张海报做多大2023年8月份新冠
  • 品牌网站建设 细致磐石网络网赌怎么推广拉客户
  • 官方网站建设 在线磐石网络全球疫情最新数据
  • cms网站后台模版seo站点是什么意思
  • 广西房地产网站建设网站优化及推广
  • 企业网站托管注意事项上海网络推广外包公司
  • 驻马店网站建设温州seo
  • 做图素材网站哪个好免费域名申请网站大全
  • 做网站的设计尺寸百度搜索引擎营销
  • 个人服务器 网站建设能够免费换友链的平台
  • 滨州网站建设百度知道首页网
  • 自助建站网信息发布平台上海seo优化
  • wordpress 仪表盘裁剪图片谷歌搜索引擎优化
  • 建商城网站crm系统成功案例分享ppt
  • 美食介绍网站模板在百度上怎么发布信息
  • 哪个网站做x展架比较好 知乎关键词优化系统
  • 手机网站的文本排版是怎么做的谷歌网站推广优化
  • 门户定制网站建设公司长沙seo外包优化
  • 做网站用python还是java河南网站推广优化
  • 西宁做网站郑州网站推广公司
  • 做网站到哪里接单同城推广有什么平台
  • 西安网站建设开发熊掌号网上seo研究
  • 做包装设计的网站竞猜世界杯
  • 西安做网站微信公司哪家好世界杯比分
  • 网站建设与维护 技能搜索引擎优化的含义和目标