i need to sort the function and to do that i have to pass it by reference however i keep getting an error. This was a combined assignment so most of the code was not done by me
using namespace std;
// This function lists out all the parts to the vector
void partList(vector<int> vect) {
for (int count = 0; count < vect.size(); count++) {
cout << "part number " << (count + 1) << " : " << vect[count] << endl;
}}
/** Function is used to sort the numbers that the user has inputted. This function will sort the numbers in ascending order. **/
void SelectionSort(vector<int> & numbers)
{
int length = numbers.size();
for (int i = 0; i < length; ++i)
{
int min = i;
for (int j = i+1; j < length; ++j) {
if (numbers[j] < numbers[min]) {
min = j;
}
if (min != i) {
int temp = numbers[i];
numbers[i] = numbers[j];
numbers[j] = temp;
}
}}
}
int main() {
vector<int> pNumbers;
int numParts;
int parts;
int yesNo;
cout << "I see that you want to create a list of parts that your company carries." << endl;
cout << "Let's start with how many part numbers you wish to add to your list: ";
cin >> numParts;
for (int count = 0; count < numParts; count++) {
int tempValue;
cout << "Please enter the part number: ";
cin >> tempValue;
pNumbers.push_back(tempValue);
}
cout << "Would you like to sort the numbers you entered? 1 for yes, 2 for no: ";
cin >> yesNo;
if(yesNo == 1) {
SelectionSort(pNumbers);
}
partList (pNumbers);
cout << "Do you wish to remove the last part number from your list? 1 for yes, 2 for no: ";
cin >> yesNo;
{
if (yesNo != 1) {
cout << "Ok. Then it seems my work here is done." << endl;
cout << "I will leave you with another copy of your list. Goodbye!" << endl;
partList(pNumbers);
}
else {
cout << "I will now be removing the last part from your list, if you do not wish to lose it, I suggest you write it down." << endl;
pNumbers.pop_back();
cout << "Here is your revised list: " << endl;
partList(pNumbers);
cout << "There, you have your list...I am done doing your dirty work, human...goodbye!" << endl;
}
}
return 0;
}