c++ has a sort() function, all you have to write is a comparison function. Here is a short tutorial
If you want to keep all the code you have already written, just replace the array with a vector, then call the vector's resize() method to initialize it to contain 10 elements. I think the rest of the program should work without change.
Ancient Dragon
Retired & Loving It
30,046 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,342
you sait you have to use vector, just replace the array with a vector as mentioned before. If you don't want number_used then delete it from the program. Give it a try and repost your most recent attempt at solving the problem.
vector<int> sample_array;
sample_array.resize(10);
Ancient Dragon
Retired & Loving It
30,046 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,342
You could always try this syntax:
vector sample_array(10);
if you want a vector of ints with space for exactly 10 ints and don't want to call resize().
If you find that the stuff you do in fill() and sort() aren't maintained in the vector in the calling function, then you will need to pass the vector by reference explicitly instead of the automatic pass by reference that happens when you pass arrays.
Oh, and to use the STL vector class you'll need to include the vector header file; and I'd move the using namespace std; line to have global scope rather than function scope so you don't have to type it twice (or more often).
Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396