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. 【LeetCode】518. Coin Change 2 解题报告(Python)

    [LeetCode]518. Coin Change 2 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目 ...

  2. Codeforces Round #358 (Div. 2) C. Alyona and the Tree

    C. Alyona and the Tree time limit per test 1 second memory limit per test 256 megabytes input standa ...

  3. 分析一个简单的goroutine资源池

    分析一个简单的goroutine资源池 tunny. 从资源池中获取goroutine并进行处理的逻辑如下: tunny将goroutine处理单元封装为workWrapper,由此可以对gorout ...

  4. 第二十八个知识点:什么是公钥密码学的IND-CCA安全定义?

    第二十八个知识点:什么是公钥密码学的IND-CCA安全定义? 我们将在这篇博客中讨论公钥加密的IND-CCA安全. IND-CCA安全代表选择明文的不可伪造性.这样的安全方案的思想就是给定一个密文,攻 ...

  5. RabbitMQ学习笔记五:RabbitMQ之优先级消息队列

    RabbitMQ优先级队列注意点: 1.只有当消费者不足,不能及时进行消费的情况下,优先级队列才会生效 2.RabbitMQ3.5以后才支持优先级队列 代码在博客:RabbitMQ学习笔记三:Java ...

  6. C# 后台发送get,post请求及WebApi接收

    后台发送get请求 1.发送带参数的get请求 /// <summary> /// 发送get请求 参数拼接在url后面 /// </summary> /// <para ...

  7. 从一堆 JAR 文件中,找出一个 Java class 文件的所在配置

    Find a class somewhere inside dozens of JAR files? find path/to/libs -name '*.jar' -exec grep -Hls C ...

  8. 解决spring boot 无法访问静态文件夹的附件或图片

    1.需要在配置文件重新执行静态文件夹位置即可 # 指定静态文件位置 resources: static-locations: classpath:/static/,classpath:/static/ ...

  9. 官方文档粗读 - Tutorial

    参考: https://www.jianshu.com/p/0d234e14b5d3 1.Connecting 我们通过 create_engine() 来链接数据库,假设我们我们采用SQLite. ...

  10. js知识框架图