I am writing a particular c++ program to use selection sort on an STL list as it is required by my professor.
I am using Netbeans 9.2. Currently, I got stuck with my algorithm. For the first few times, the program compiles but the list after selection always ends up with the same values(say it was supposed to be 99, 24, 15, 80, 27, it would always be 1, 1, 1, 1, 2 after the sort). Now the algorithm just straight up wouldn't compile. I am relatively new to coding. Could someone please tell me what I've gotten wrong and how I should go about it? Much thanks!
Here's my code:
void selectionSort(list<short> l, int size) {
list<short>::iterator it1;
list<short>::iterator it2;
list<short>::iterator it3;
short min, temp;
for(it1 = l.begin(); it1 != l.end(); it1++) {
temp = min = *it1;
it2 = it1;
for(it2 = it1; it2 != l.end(); it2++) {
if(*it2 < min) {
min = *it2;
it3 = it2;
}
}
*it1 = min;
*it3 = temp;
//Increment the first counter at the end
temp = min = *it1;
}
}