STL-Standard Template Library(标准模板库)
Java没有函数模板的概念
- STL是一个C++软件库
包含算法、容器和迭代器三大类,其中算法以函数模板的形式提供了交换、查找、替换、逆序、排序等功能。使用任何一个函数模板都要求包含头文件:
#include <algorithm> //algorithm 算法
- 交换函数swap——交换两个变元的值
#include<iostream>
#include<algorithm>
using namespace std;
//void swap(T &a,T &b) //&a是一个引用,是变量的别名
int main()
{
double x,y;
cin>>x>>y;
swap(x,y);
cout<<x<<y<<endl;
}
- 排序函数sort——将数组中元素升序排列
#include<iostream>
#