1、array数组

#include<iostream>
#include<array>
using namespace std; int main()
{
array<int, 10> marray;//使用array方法 for (int i = 0; i < 10; i++)//向marray赋值
{
marray[i] = i;
} cout << "遍历数据" << endl;
for (auto it = marray.begin(); it != marray.end(); it++)
cout << *it << '\t'; cout << endl;
cout << "size of array is " << marray.size() << endl; cout << "第四个元素为:" << marray[3] << endl; return 0;
}

2、queue队列

#include<iostream>
#include<array>
#include<queue> //头文件
using namespace std; int main()
{
queue<int> mqueue; //队列初始化
for (int i = 0; i < 10; i++)
{
mqueue.push(i); //向其中添加数据
} while (!mqueue.empty())
{
cout << mqueue.front() << endl;//获取头部数据
mqueue.pop(); //弹出头部数据
}
return 0;
}

3、stack栈

#include<iostream>
#include<stack>
using namespace std; int main()
{
stack<int> mstack; for (int i = 0; i < 10; i++)
mstack.push(i); while (!mstack.empty())
{
cout << mstack.top() << endl;//取栈顶元素
mstack.pop();//弹出栈顶元素
}
return 0;
}

4、list链表

#include<iostream>
#include<list>
using namespace std; int main()
{
int num[] = {
1,2,3,4,5
};
list<int> mlist(num, num + sizeof(num) / sizeof(int)); for (auto it = mlist.begin(); it != mlist.end(); it++)
{
cout << *it << " ";
} auto it = mlist.begin();
for (int i = 0; i < 5; i++)
{
mlist.insert(it, i);
} cout << endl;
for (auto it = mlist.begin(); it != mlist.end(); it++)
cout << *it << " "; return 0;
}

5、map

map是一个容器,有一一对应的特点。

#include<iostream>
#include<map>
using namespace std; int main()
{
map<char, int> mmap;//初始化 mmap['a'] = 1; mmap.insert(pair<char, int>('b',2));//插入 mmap.erase('a');//删除 auto it = mmap.find('b');//查找
cout << it->first << " " << it->second << endl; return 0;
}

6、set集合

set集合最大的特点是里面的元素按序排列不重复,图片演示集合初始化、插入、删除、查找等操作。

#include<iostream>
#include<set>
using namespace std; int main()
{
int num[] = {
1,2,3,4,5
};
set<int> myset(num, num + sizeof(num) / sizeof(int)); myset.insert(6);//插入 myset.erase(2);//删除 auto it = myset.find(3);//查找 cout << *it << endl; return 0;
}

7、vector向量

vector向量和array不同,它可以根据数据的大小而进行自动调整,图片仅展示初始化、插入、删除等操作。

#include<iostream>
#include<vector>
using namespace std; int main()
{
vector<int> myvector; for (int i = 0; i < 10; i++)
{
myvector.push_back(i);//压入
} for (auto it = myvector.begin(); it != myvector.end(); it++)//遍历
{
cout << *it << endl;
} return 0;
}

C++数据结构类型以及实现类的更多相关文章

  1. C++中结构体与类的区别(结构不能被继承,默认是public,在堆栈中创建,是值类型,而类是引用类型)good

    结构是一种用关键字struct声明的自定义数据类型.与类相似,也可以包含构造函数,常数,字段,方法,属性,索引器,运算符和嵌套类型等,不过,结构是值类型. 1.结构的构造函数和类的构造函数不同. a. ...

  2. Json序列反序列类型处理帮助类

    Json序列反序列类型处理帮助类. JSON反序列化 JSON序列化 将Json序列化的时间由/Date(1294499956278+0800)转为字符串 将时间字符串转为Json时间 using S ...

  3. 工具类:将其他编码类型转换成UTF-8或者其他类型的工具类

    将其他编码类型转换成UTF-8或者其他类型的工具类 public static String changeUTF(String str) { String newStr = null; try { n ...

  4. python中对象、类型和元类之间的关系

    在python中对象.类型和元类构成了一个微妙的世界. 他们有在这个世界里和平共处,相辅相成.它们遵循着几条亘古不变的定律: 1.python中无处不对象 2.所有对象都有三种特性:id.类型.值 3 ...

  5. 将泛类型集合List类转换成DataTable

    /// <summary> /// 将泛类型集合List类转换成DataTable /// </summary> /// <param name="list&q ...

  6. Redis的值value(数据结构类型)

    Redis的数据结构类型,指的是redis的值的value类型: Redis的常用数据结构类型:string,list,set,sortedSet,hash 一.sting的类型 string类型是r ...

  7. redis 全局命令 查看所有的键,删除键,检查键是否存在,获取过期时间,键的数据结构类型

    Redis有5中数据结构,他们是键值对中的值,对于键来说,有一些通用的命令: 一.查看所有键 keys * 二.获取键总数:dbsize 三.检查键是否存在 exists 如果存在返回1,不存在返回0 ...

  8. .NET基础 (11)类型的基类System.Object

    类型的基类System.Object1 是否存在不继承自System.Object类型的类2 在System.Object中定义的三个比较方法有何异同3 如何重写GetHashCode方法 类型的基类 ...

  9. 只要实现了annotation这个接口就是注解 同理:只要实现了某个接口就是该类型的实现类

    只要实现了annotation这个接口就是注解  同理:只要实现了某个接口就是该类型的实现类

随机推荐

  1. ubuntu ffmpeg 转码错误

    [aac @ 0xde2400] The encoder 'aac' is experimental but experimental codecs are not enabled, add '-st ...

  2. 一个自定义的c++错误类 和 同步异步、阻塞非阻塞(区别简述)

    一个例子,自定义exception 继承std::exception 1 class _oct_udp_api_export_ udp_err : public std::exception 2 { ...

  3. C++基础之自增和自减运算符的重载

    1. 格式 1.1 分为前置和后置格式: int x = 0; int y = 0; // 后置自增运算符 x++; // 前置自增运算符 ++x; // 后置自减运算符 y--; // 前置自减运算 ...

  4. 【LeetCode】1160. Find Words That Can Be Formed by Characters 解题报告(C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典统计 日期 题目地址:https://leetco ...

  5. 【LeetCode】155. Min Stack 最小栈 (Python&C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 解题方法 栈同时保存当前值和最小值 辅助栈 同步栈 不同步栈 日期 题目地 ...

  6. Codeforce C. Pearls in a Row

    C. Pearls in a Row time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  7. 1686 第K大区间

    1686 第K大区间 时间限制:1 秒 空间限制:131072 KB   定义一个区间的值为其众数出现的次数.现给出n个数,求将所有区间的值排序后,第K大的值为多少. 众数(统计学/数学名词)_百度百 ...

  8. 第四十二个知识点:看看你的C代码为蒙哥马利乘法,你能确定它可能在哪里泄漏侧信道路吗?

    第四十二个知识点:看看你的C代码为蒙哥马利乘法,你能确定它可能在哪里泄漏侧信道路吗? 几个月前(回到3月份),您可能还记得我在这个系列的52件东西中发布了第23件(可以在这里找到).这篇文章的标题是& ...

  9. 读书笔记markdown模板

    读书笔记 书名 作者 出版社 阅读日期 书籍背景 书摘/ 笔记 批注 总结& 收获 读完每一本书,把书中的知识转化为「自己的智慧」,才是最扎实的收获- 他山之石 摘录相关精彩书评-

  10. 关于 base64 编码

    一.什么是Base64编码 Base64是一种用64个字符来表示任意二进制数据的方法.它是一种编码方式,而非加密方式.它通过将二进制数据转变为64个"可打印字符",完成了数据在HT ...