Hey guys.
I am writing a rather large program and there is a part that I want to sort 10 entered vales from the keyboard. Would it be more efficient to use bubblesort or the sort() function using a vector / iterator?
I was thinking of somthing like this as I am leaning towards the vector:
I am only asking as I am trying to conserve space and I know that a vector is a more robust type of array.Code:std::vector<int> scores( 10, 0 );
std::vector<int>::iterator iter;
std::cout << "Enter 10 integers: ";
// add values to vector elements
for ( int i = 0; i < scores.size(); i++ )
{
std::cin >> scores[ i ];
}
std::cout << "\n\nYou entered:\n\n";
for ( iter = scores.begin(); iter != scores.end(); ++iter )
{
std::cout << *iter << std::endl;
}
std::cout << "\n\nSorted into order:\n\n";
sort ( scores.begin(), scores.end());
for ( iter = scores.begin(); iter != scores.end(); ++iter )
{
std::cout << *iter << std::endl;
}
Thanks in advance for any input.