C++ 向量排序问题

来源:百度知道 编辑:UC知道 时间:2024/05/10 19:17:14
请个高手来看看 下面是我写的小程序,主函数中调用的排序函数sort(sample); 为什么没有效果 输出的数据还是没排序前的
高手能不能帮忙看看是什么问题
#include <iostream>
#include <vector>
using namespace std;

void sort(vector<int> v);

void swap_values(int& v1, int& v2);

int index_of_smallest(const vector<int> v, int start_index);

int main()
{
vector<int> sample;
cout << "Enter a list of positive numbers.\n"
<< "Place a negative number at the end.\n";

int next;
cin >> next;
while (next > 0)
{
sample.push_back(next);
cin >> next;
}

sort(sample);

cout << "In sorted order the numbers are:\n";
for (unsigned int i = 0; i < sample.size(); i++)
cout << sample[i] << " ";
cout << endl;

return 0;
}

void sort(vector<int

//---------------------------------------------------------------------------

#pragma hdrstop

//---------------------------------------------------------------------------

#pragma argsused
#include <iostream>
#include <vector>
#include <conio.h>
using namespace std;

void sort(vector<int>& v);

void swap_values(int& v1, int& v2);

int index_of_smallest(const vector<int>& v, int start_index);

int main()
{
vector<int> sample;
cout << "Enter a list of positive numbers.\n"
<< "Place a negative number at the end.\n";

int next;
cin >> next;
while (next > 0)
{
sample.push_back(next);
cin >> next;
}

sort(sample);

cout << "In sorted order the numbers are:\n";
for (unsigned int i = 0; i <