vector理论知识(学习)

vector理论知识

vector就是数组在C++中的另一种称呼,vector之所以被认为是一个容器,是因为它能够像容器一样存放各种类型的对象,简单地说,vector是一个能够存放任意类型的动态数组,能够增加和压缩数据。
vector类型与数组类型比较:

  • vector类型长度是动态的,可以根据需要动态的调用push_back函数添加新的元素,而数组的长度是固定的;
  • 数组没有获取数组大小的函数,而vector类型提供size函数能够方便的获取容器的大小;
  • 现代C++程序应尽量使用vector和迭代器类型,而避免使用低级的数组指针,只有在强调程序的速度时才在类实现的内部使用数组和指针。

头文件:#include <vector>
还需加全域名:using namespace std;
vector 的定义和初始化 四种方法:
1. vector v1; 例如:vector v1; 表示定义了一个整型数组,元素的值为0
2. vector v2(v1); 例如 vector v2(v1) 表示定义了一个v2数组,并用v1进行初始化;
3. vector v3(n,i); 例如vectorv3(5,10)表示定义了一个v3数组,有5个元素,初始值都为10;
4. vector v4(n); 例如vector v4(5)表示定义了一个字符串的v4数组,有5个元素。


向vector添加一个数据
push_back()函数表示将数据添加到vector的尾部,并按需要来分配内存。

vector插入一个数据
s.insert(it, x)
向迭代器it指向的元素前插入新元素val。
s.insert(it, n, x)
向迭代器it指向的元素前插入n个x。
s.insert(it, first, last)
将由迭代器first和last所指定的序列[first, last)插入到迭代器it指向的元素前面。

删除vector中的数据
vector提供了
erase()【v.erase(v.begin()+2);删除第3元素vec.erase(vec.begin()+i,vec.end()+j);删除区间[i,j-1]】,
pop_back(),【可以高效地移除vector中的最后一个元素】
clear()【清空】
来删除数据,当你删除数据的时候,你应该知道要删除尾部的数据,或者是删除所有数据,还是个别的数据。

vector大小
size(); empty();

vector的遍历
下标法(类似数组),at()函数。
使用迭代器访问元素:

//vector的begin(), end()它们分别指向“向量开始处”和“结束处后一个”的迭代器
vector<int>::iterator x;
for(x=vec.begin();x!=vec.end();x++)
    cout<<*x<<endl;

其他函数:
http://blog.csdn.net/phoebin/article/details/3864590#comments

s.front()
返回首元素。

s.back()
返回尾元素。

s.reserve(n)
预分配缓冲空间,使存储空间至少可容纳n个元素。

s.resize(n)
改变序列的长度,超出的元素将会被删除,如果序列需要扩展(原空间小于n),元素默认值将填满扩展出的空间。
s.resize(n, val)
改变序列的长度,超出的元素将会被删除,如果序列需要扩展(原空间小于n),将用val填满扩展出的空间。

s.swap(v)
将s与另一个vector对象v进行交换。

。。。。。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
【摘要】 学习是一切智能系统最根本的特征。机器学习是人工智能最具智能特征、最前沿的研究领域之一。机器学习研究的是如何使机器通过识别和利用现有知识来获取新知识和新技能。机器学习就是要使计算机能模拟人的学习行为,自动地通过学习获取知识和技能,不断改善性能,实现自我完善。 与传统统计学相比,统计学习理论是一种专门研究小样本情况下机器学习规律的理论。V.Vapnik 等人从六、七十年代开始致力于此方面研究,到九十年代中期,其理论不断发展和成熟。统计学习理论是建立在一套较坚实的理论基础之上的,为解决有限样本学习问题提供了一个统一的框架,它能将很多现有方法纳入其中,同时,在这一理论基础上发展了一种新的通用学习方法——支持向量机(Support Vector Machine 或 SVM),它已初步表现出很多优于已有方法的性能。 本文对机器学习、支持向量机的研究现状及应用领域进行了综述,阐述了机器学习和支持向量机的基本概念、基本模型和支持向量机的训练算法。针对机器学习系统的具体结构,提出了机器学习系统的模块化设计,划分出了输入处理、训练、执行与评价、评价表示 4 个模块,设计了各个模块之间的通信方式,并具体实现了 4 个模块和模块集成系统。 根据基于支持向量机的机器学习的研究成果,研制开发出人脸检测系统,主要包括人脸图像处理和编码、基于支持向量机的机器学习、执行与评价、评价表示功能,实现了人脸的自动判定。 还原 【Abstract】 Learning is the fundamental feather of all intelligent system.machine-learning is a domain with most intelligent feather and a domain with most foreland.machine-learning research how to obtain new knowledge and new technique by recognition and using existing knowledge.machine-learning let computer simulate man’s learning-action,automatically obtain new knowledge and new technique by learn,improve technique,realize own-perfect. To traditional statistics,Statistical Learning Theory is a theory of researching rule of machine-learning under little sample number.From 1960’s,V.Vapnik etc. begin to research this theory.To middle of 1990’s,this theory increasivly improved and completed.Statistical Learning Theory build on a set of stabile theory,offer a united framework to resolve little sample learning question,it can hold lots of existing method,and it build a new currency learning method--Support Vector Machine,Support Vector Machine method had represent better performance than existing method. This article summarize today state and application domain of machine-learning and Support Vector Machine,expound basic concept and basic model of machine-learning and Support Vector Machine and training arithmetic of Support Vector Machine.Aim at structure of machine-learning system,this article put forward module-design of machine-learning system,partition four module:deal-input,train,evaluate and evaluate representation,and design communicate style of each module,realize this four module and module-integration system. On result of researching machine-learning based Support Vector Machine,Face-Detection system is producted.This system mainly include dealing image of man-face and encode,machine-learning based Support Vector Machine,evaluate and evaluate representation,realize automatically judging man-face. 还原

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值