cin>>num[i];
for(int i=0;i<5;i++)
cout<<num[i]<<" ";
return 0;
}
//运行结果:
/*
1 2 3 4 5
1
2
3
4
5
Process returned 0 (0x0) execution time : 3.516 s
Press any key to continue.
*/
//第二种源代码:
#include
#include
using namespace std;
int main()
{
vector num (5);
for(int i=0;i<5;i++)
cin>>num[i];
//向数组中插入数字
num.push_back(6);//在向量尾部插入6
//遍历打印
for(int i=0;i<num.size();i++) //.size可以测矢量的长度
cout<<num[i]<<endl;
return 0;
}
/* 运行结果:
1 2 3 4 5
1
2
3
4
5
6
Process returned 0 (0x0) execution time : 5.465 s
Press any key to continue.
*/
// 第三种:
#include
#include
using namespace std;
int main()
{
vector num (5);
for(int i=0;i<5;i++)
cin>>num[i];
//向数组中插入数字
num.push_back(6);//在向量尾部插入6
//遍历打印
//使用迭代器 iterator
//以下是迭代器的基本用法,高能慎用!!!!
vector::iterator it; //得到迭代对象,实际上是一个指针
//it.begin
//从第一个元素迭代
for(it=num.begin();it!=num.end();++it) //如果使用it++,则会有缓存现象,导致效率不高
{
cout<<* it<<endl;
}
return 0;
}
// 运行结果:
/*
2 5 7 9 3
2
5
7
9
3
6
Process returned 0 (0x0) execution time : 4.587 s
Press any key to continue.
*/
//下面演示一下使用快排
#include
#include
#include //算法
using namespace std;
int main()
{
vector num (5);
for(int i=0;i<5;i++)
cin>>num[i];
//向数组中插入数字
num.push_back(6);//在向量尾部插入6
//遍历打印
//使用迭代器 iterator
//以下是迭代器的基本用法,高能慎用!!!!
vector::iterator it; //得到迭代对象,实际上是一个指针
//it.begin
//从第一个元素迭代
for(it=num.begin();it!=num.end();++it) //如果使用it++,则会有缓存现象,导致效率不高
{
cout<<* it<<endl;
}
sort(num.begin(),num.end());
cout<<endl<<endl;
for(it=num.begin();it!=num.end();++it) //如果使用it++,则会有缓存现象,导致效率不高
{
cout<<* it<<endl;
}
return 0;
}
//输出结果:
/*
1 7 9 3 4
1
7
9
3
4
6
1
3
4
6
7
9
Process returned 0 (0x0) execution time : 7.554 s
Press any key to continue.
*/
// 逆序
#include
#include
#include //算法
using namespace std;
int main()
{
vector num (5);
for(int i=0;i<5;i++)
cin>>num[i];
//向数组中插入数字
num.push_back(6);//在向量尾部插入6
//遍历打印
//使用迭代器 iterator
//以下是迭代器的基本用法,高能慎用!!!!
vector::iterator it; //得到迭代对象,实际上是一个指针
//it.begin
//从第一个元素迭代
for(it=num.begin();it!=num.end();++it) //如果使用it++,则会有缓存现象,导致效率不高
{
cout<<* it<<endl;
}
reverse(num.begin(),num.end()); //逆序排序
cout<<endl<<endl;
for(it=num.begin();it!=num.end();++it) //如果使用it++,则会有缓存现象,导致效率不高
{
cout<<* it<<endl;
}
return 0;
}
//输出结果:
1 2 3 4 5
1
2
3
4
5
6
6
5
4
3
2
1
Process returned 0 (0x0) execution time : 8.155 s
Press any key to continue.
*/
3.矢量中的常见函数
==============
clear() | 清除容器中所有数据 |
empty() | 判断容器是否为空 |
size() | 返回容器元素的个数 |
front() | 返回第一个元素 |
insert(pos,num) | 在POS位置插入一个数字 |
pop_back() | 在容器删除最后一个元素 |
push_back() | 在容器末尾加入一个元素 |
resize(num) | 重新设置容器大小 |
begin(),end() | 返回容器首尾元素的迭代器 |
4.从矢量中删除元素
==========
用法示例:
#include
#include
#include //算法
using namespace std;
int main()
{
vector num (5);
for(int i=0;i<5;i++)
cin>>num[i];
num.pop_back();
//遍历打印
//使用迭代器 iterator
//以下是迭代器的基本用法,高能慎用!!!!
vector::iterator it; //得到迭代对象,实际上是一个指针
//it.begin
//从第一个元素迭代
for(it=num.begin();it!=num.end();++it) //如果使用it++,则会有缓存现象,导致效率不高
{
cout<<* it<<endl;
}
return 0;
}
//输出结果:
1 3 5 6 7
1
3
5
6
Process returned 0 (0x0) execution time : 4.096 s
Press any key to continue.
5.清理矢量
==========
用法示例:
#include
#include
#include //算法
using namespace std;
int main()
{
vector num (5);
for(int i=0;i<5;i++)
cin>>num[i];
//遍历打印
//使用迭代器 iterator
//以下是迭代器的基本用法,高能慎用!!!!
vector::iterator it; //得到迭代对象,实际上是一个指针
//it.begin
//从第一个元素迭代
for(it=num.begin();it!=num.end();++it) //如果使用it++,则会有缓存现象,导致效率不高
{
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则近万的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:Android)
最后
跳槽季整理面试题已经成了我多年的习惯!在这里我和身边一些朋友特意整理了一份快速进阶为Android高级工程师的系统且全面的学习资料。涵盖了Android初级——Android高级架构师进阶必备的一些学习技能。
附上:我们之前因为秋招收集的二十套一二线互联网公司Android面试真题(含BAT、小米、华为、美团、滴滴)和我自己整理Android复习笔记(包含Android基础知识点、Android扩展知识点、Android源码解析、设计模式汇总、Gradle知识点、常见算法题汇总。)
《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!
续更新!**
如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:Android)
最后
跳槽季整理面试题已经成了我多年的习惯!在这里我和身边一些朋友特意整理了一份快速进阶为Android高级工程师的系统且全面的学习资料。涵盖了Android初级——Android高级架构师进阶必备的一些学习技能。
附上:我们之前因为秋招收集的二十套一二线互联网公司Android面试真题(含BAT、小米、华为、美团、滴滴)和我自己整理Android复习笔记(包含Android基础知识点、Android扩展知识点、Android源码解析、设计模式汇总、Gradle知识点、常见算法题汇总。)
[外链图片转存中…(img-gwu9DvOy-1713299465681)]
《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!