#include <iostream>Almost like Bjarne Stroustrup:
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
vector<int> v;
int input;
while (cin >> input)
{
if (input == 0)
break;
v.push_back(input);
}
sort(v.begin(), v.end());
int n = v.size();
for (int i = 0; i < n; i++)
cout << "v[" << i << "] = " << v[i] << endl;
return 0;
}
http://www2.research.att.com/~bs/bs_faq2.html
This program uses the simplest STL container vector and performs the sorting by calling sort STL function. This function works with the iterators - it gets the first iterator and increments and dereference it until it is equal to the second iterator.
No comments:
Post a Comment