I am trying to perform selection sort watching the pseudocode which says "we take the first element and then check for the minimum element excluding the first element, once found we swap the minimum with the first and the first points to the next element and the process goes on..." i tried to code but i am getting the same vector which i provided there is no sorting happening why is that?
#include <bits/stdc++.h>
using namespace std;
void selection(vector <int>& vp, int &n)
{
for(int i=0;i<n;i++)
{
int sorted=vp[i];
int iterator = i+1;
int min=INT_MAX;
while(iterator<n)
{
if(vp[iterator]<min)
{
min=vp[iterator];
}
iterator++;
}
swap(sorted,min);
}
for(int i=0;i<n;i++)
{
cout<<vp[i]<<" ";
}
}
int main()
{
vector <int> vp{12,45,23,51,19,8};
int n = vp.size();
selection(vp,n);
}