【发布时间】:2015-07-27 03:37:28
【问题描述】:
我正在尝试使用向量从最小到最大对某些数字进行排序。当我尝试运行我的代码时,它只显示 ----PRINT----- 和 ---END--- 我卡住了。我在想它是否与排序过程中的修复功能有关。
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
void print(vector<int> vec)
{
cout<< "------PRINT---------"<< endl;
for (vector<int>::const_iterator it=vec.begin(); it!=vec.end(); ++it)
cout << *it << " ";
cout << "------ END ------" << endl;
}
vector<int> fix(vector<string> numbers)
{
vector<int> result;
sort( result.begin(), result.end() );
return result;
}
int main()
{
vector<string> test;
test.push_back("5462");
test.push_back("5451");
test.push_back("7854");
test.push_back("221");
print(fix(test));
return 0;
}
【问题讨论】:
标签: c++ algorithm sorting vector