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. 再谈多线程模型之生产者消费者(基础概念)(c++11实现)

    0.关于 为缩短篇幅,本系列记录如下: 再谈多线程模型之生产者消费者(基础概念)(c++11实现)[本文] 再谈多线程模型之生产者消费者(单一生产者和单一消费者)(c++11实现) 再谈多线程模型之生 ...

  2. 【LeetCode】389. Find the Difference 解题报告(Java & Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:字典统计次数 方法二:异或 方法三:排序 日 ...

  3. 【九度OJ】题目1124:Digital Roots 解题报告

    [九度OJ]题目1124:Digital Roots 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1124 题目描述: T ...

  4. 【LeetCode】731. My Calendar II 解题报告(Python)

    [LeetCode]731. My Calendar II 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题 ...

  5. J. Bottles

    J. Bottles time limit per test 2 seconds memory limit per test 512 megabytes input standard input ou ...

  6. P1753HackSon的趣味题

    1 #include<stdio.h> 2 #include<algorithm> 3 #include<iostream> 4 #include<stdli ...

  7. 『学了就忘』vim编辑器基础 — 96、末行模式中的相关命令

    目录 1.在文档中显示行号 2.是否显示文档内容相关颜色 3.是否将查找的字符串高亮显示 4.是否显示右下角的状态栏 5.是否在左下角显示如"--INSERT--"之类的状态栏 6 ...

  8. 【感悟】观《BBC彩色二战纪录片》有感

    2020年7月2日到3日我看了纪录片,以下是我的一些感悟 1.作为进攻者,无论大事还是小事都需要一鼓作气做完,以免留给对手喘息的机会.(指:未消灭) 2.作为防守者,要有顽强抵抗的精神,但要保留撤退的 ...

  9. 详解Kalman Filter

    中心思想 现有: 已知上一刻状态,预测下一刻状态的方法,能得到一个"预测值".(当然这个估计值是有误差的) 某种测量方法,可以测量出系统状态的"测量值".(当然 ...

  10. .NET 云原生架构师训练营(ASP .NET Core 整体概念推演)--学习笔记

    演化与完善整体概念 ASP .NET Core 整体概念推演 整体概念推演到具体的形式 ASP .NET Core 整体概念推演 ASP .NET Core 其实就是通过 web framework ...