C++数据结构类型以及实现类
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++数据结构类型以及实现类的更多相关文章
- C++中结构体与类的区别(结构不能被继承,默认是public,在堆栈中创建,是值类型,而类是引用类型)good
结构是一种用关键字struct声明的自定义数据类型.与类相似,也可以包含构造函数,常数,字段,方法,属性,索引器,运算符和嵌套类型等,不过,结构是值类型. 1.结构的构造函数和类的构造函数不同. a. ...
- Json序列反序列类型处理帮助类
Json序列反序列类型处理帮助类. JSON反序列化 JSON序列化 将Json序列化的时间由/Date(1294499956278+0800)转为字符串 将时间字符串转为Json时间 using S ...
- 工具类:将其他编码类型转换成UTF-8或者其他类型的工具类
将其他编码类型转换成UTF-8或者其他类型的工具类 public static String changeUTF(String str) { String newStr = null; try { n ...
- python中对象、类型和元类之间的关系
在python中对象.类型和元类构成了一个微妙的世界. 他们有在这个世界里和平共处,相辅相成.它们遵循着几条亘古不变的定律: 1.python中无处不对象 2.所有对象都有三种特性:id.类型.值 3 ...
- 将泛类型集合List类转换成DataTable
/// <summary> /// 将泛类型集合List类转换成DataTable /// </summary> /// <param name="list&q ...
- Redis的值value(数据结构类型)
Redis的数据结构类型,指的是redis的值的value类型: Redis的常用数据结构类型:string,list,set,sortedSet,hash 一.sting的类型 string类型是r ...
- redis 全局命令 查看所有的键,删除键,检查键是否存在,获取过期时间,键的数据结构类型
Redis有5中数据结构,他们是键值对中的值,对于键来说,有一些通用的命令: 一.查看所有键 keys * 二.获取键总数:dbsize 三.检查键是否存在 exists 如果存在返回1,不存在返回0 ...
- .NET基础 (11)类型的基类System.Object
类型的基类System.Object1 是否存在不继承自System.Object类型的类2 在System.Object中定义的三个比较方法有何异同3 如何重写GetHashCode方法 类型的基类 ...
- 只要实现了annotation这个接口就是注解 同理:只要实现了某个接口就是该类型的实现类
只要实现了annotation这个接口就是注解 同理:只要实现了某个接口就是该类型的实现类
随机推荐
- c++之升序和降序排序
1.头文件 #include <functional> 2. 降序 // 期末成绩 int score[] = {99, 77, 30, 80}; // 1. 降序排列 std::sort ...
- 【LeetCode】544. Output Contest Matches 解题报告 (C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 遍历 日期 题目地址:https://leetcode ...
- ZOJ 3872: Beauty of Array(思维)
Beauty of Array Time Limit: 2 Seconds Memory Limit: 65536 KB Edward has an array A with N integers. ...
- 应用程序开发 WebApp NativeApp 微信小程序
Web Native App 微信小程序 WebApp是指基于Web的系统和应用,其作用是向广大的最终用户发布一组复杂的内容和功能.webapp 框架是一种简单的与WSGI兼容的网络应用程序框 ...
- The Expressive Power of Neural Networks: A View from the Width
目录 概 主要内容 定理1 定理2 定理3 定理4 定理1的证明 Lu Z, Pu H, Wang F, et al. The expressive power of neural networks: ...
- vue 滚动公告
<!-- 滚动公告 --> <div class="textArr"> <p class="slice-enter-active" ...
- 应用TYPE-C外围电源管理IC IM2605
应用于TYPE-C外围集成同步4开关Buck-Boost变换器的电源管理IC IM2605 IM2605描述 IM2605集成了一个同步4开关Buck-Boost变换器,在输入电压小于或大于输出电 ...
- CS5210完全替代AG6202|HDMI转VGA芯片+原理图|替代兼容AG6202
安格AG6202是一个HDMI转VGA不带音频解决方案,用于实现HDMI1.4高分辨率视频转VGA转换器.Capstone CS5210不管在性能上和设计参数上面都是可以完全替代安格AG6202,且 ...
- <数据结构>XDOJ317.输出完全二叉树的某一层
问题与解答 问题描述 对一棵完全二叉树,输出某一深度的所有节点,有则输出这些节点,无则输出EMPTY. 输入格式 输入有多组数据. 每组数据第一行输入一个结点数n(1<=n<=1000), ...
- 【计项02组01号】Java版图形界面计算器
Java版图形界面计算器1.0版本 项目分析[1.0] 组成部分 代码结构 (1)窗口的创建 在<JDK 核心 API>中我们提到,创建一个窗口需要使用 JFrame 类.在本实验中,我们 ...