有谁知道从begin到end结束这一段怎么写,谁能帮忙回答一下,求
思路一:根据两个数的各个位至与变换后的位置的倍数关系进行乘车再把所有位置乘除结果相加
思路二:转字符串-》分割字符串-》拼接字符串-》转int
#include <iostream>
#include <algorithm>
using namespace std;
template<typename T, typename S>
void mysort(T begin, T end, S cmp) {
for (T i = begin; i != end; ++i) {
for (T j = i + 1; j != end; ++j) {
if((*cmp)(*i, *j))
swap(*i, *j);
}
}
}
bool Greater2(int n1, int n2)
{
return n1 > n2;
}
bool Greater1(int n1, int n2)
{
return n1 < n2;
}
bool Greater3(double d1, double d2)
{
return d1 < d2;
}
#define NUM 5
int main()
{
int an[NUM] = { 8,123,11,10,4 };
mysort(an, an + NUM, Greater1); //从小到大排序
for (int i = 0; i < NUM; i++)
cout << an[i] << ",";
mysort(an, an + NUM, Greater2); //从大到小排序
cout << endl;
for (int i = 0; i < NUM; i++)
cout << an[i] << ",";
cout << endl;
double d[6] = { 1.4,1.8,3.2,1.2,3.1,2.1 };
mysort(d + 1, d + 5, Greater3); //将数组从下标1到下标4从小到大排序
for (int i = 0; i < 6; i++)
cout << d[i] << ",";
return 0;
}