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++)实现

    !!版权声明:本文为博主原创文章,版权归原文作者和博客园共有,谢绝任何形式的 转载!! 作者:mohist -- 欢迎指正-- 平衡二叉树特点: 任意一个结点的平衡因子(左子树高度 - 右子树高度)的 ...

  2. FilesCodingConvert--批量文件编码格式转换工具

    FilesCodingConvert–批量文件编码格式转换工具 简介 最近开始学习使用Android Studio,因为它的方便易用,我打算以后就不在使用ADT的方式编写Android项目了.当从Ec ...

  3. 【LeetCode】688. Knight Probability in Chessboard 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/knight-pr ...

  4. 【LeetCode】863. All Nodes Distance K in Binary Tree 解题报告(Python)

    [LeetCode]863. All Nodes Distance K in Binary Tree 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http ...

  5. 更快的Maven来了,我的天,速度提升了8倍!

    周末被 maven-mvnd 刷屏了,于是我也下载了一个 mvnd 体验了一把.虽然测试的数据都是基于我本地项目,不具备普适性和权威性,但也足以说明问题.它的测试结果远远超出我的预期,下面一起来看. ...

  6. 【MySQL作业】MySQL函数——美和易思字符串函数应用习题

    点击打开所使用到的数据库>>> 1.将所有客户的姓名与电话以"-"作为分隔符进行连接显示. 使用 concat(s1,s2,-) 函数将所有客户的姓名与电话以&q ...

  7. 编写Java程序,编写自定义异常类封装将棋子落在格子中已有棋子的异常

    返回本章节 返回作业目录 需求说明: 完善控制台版五子棋,判断用户所下棋子的位置,是否已经存在棋子,如果已经存在,则抛出用户自定义异常,提示用户该位置已经有棋子. 实现思路: 创建用户自定义异常类Go ...

  8. MongoDB高级应用之高可用方案实战(4)

    1.MongDB启动与关闭 1.1.命令行启动 ./mongod --fork --dbpath=/opt/mongodb/data ----logpath=/opt/mongodb/log/mong ...

  9. nignx-防盗链

    环境 主机                  IP            角色 centos6.5-1       192.168.3.10      源主机 centos6.5-2       19 ...

  10. Count Sequences

    \(考虑问题的转换,即把用n个球,分为r-l+2个部分,其中第1部分表示该区域的球值为l,第二部分表示该区域的球值为l+1\) \(......第r-l+2部分为不选该区域的球\) \(该问题等价于在 ...