代码主要显示了迭代器使用泛型算法
#include <vecotor>
#include <algorithm>
#include <iostream>
int ia[10] = {51,23,7,88,41,98,12,103,37,6};
int main()
{
vector < int > vec( ia, ia+10);
// 排序数组
sort ( vec.begin(), vec.end() ):
// 获取值
int search_value;
cin >> search_value;
// 搜索元素
vector < int > :: iterator found;
found = find ( vec.begin(), vec.end(), search_value);
if ( found != vec.end() )
cout << "search_value not found!/n";
// 反转数组
reverse( vec.begin(), vec.end() );
// ....
}
#include <vecotor>
#include <algorithm>
#include <iostream>
int ia[10] = {51,23,7,88,41,98,12,103,37,6};
int main()
{
vector < int > vec( ia, ia+10);
// 排序数组
sort ( vec.begin(), vec.end() ):
// 获取值
int search_value;
cin >> search_value;
// 搜索元素
vector < int > :: iterator found;
found = find ( vec.begin(), vec.end(), search_value);
if ( found != vec.end() )
cout << "search_value not found!/n";
// 反转数组
reverse( vec.begin(), vec.end() );
// ....
}