声明一个整型数组,使用C++标准模版库(STL)中的查找算法find()进行数据的查找,然后应用排序算法sort(
展开全部
#include <iostream>
using std::cout;
using std::endl;
#include <algorithm>
#include <functional>
void print(int *begin, int *end) {
while (begin != end)
cout << *begin++ << " ";
cout << endl;
}
int main()
{
int array[] = { 1, 4, 2, 3, 5, };
cout << "looking for 3: " << endl;
cout << *(std::find(array, array + 5, 3)) << endl;
cout << "sorting ascending" << endl;
std::sort(array, array + 5);
print(array, array + 5);
cout << "sorting descending" << endl;
std::sort(array, array + 5, std::greater<int>());
print(array, array + 5);
return 0;
}
using std::cout;
using std::endl;
#include <algorithm>
#include <functional>
void print(int *begin, int *end) {
while (begin != end)
cout << *begin++ << " ";
cout << endl;
}
int main()
{
int array[] = { 1, 4, 2, 3, 5, };
cout << "looking for 3: " << endl;
cout << *(std::find(array, array + 5, 3)) << endl;
cout << "sorting ascending" << endl;
std::sort(array, array + 5);
print(array, array + 5);
cout << "sorting descending" << endl;
std::sort(array, array + 5, std::greater<int>());
print(array, array + 5);
return 0;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询