c++ code for selection sort
#include
using namespace std;
int main(){
//selection sort
int a[5] = {54,69,12,2,89};
//find minimum in rest of the array and swap with the current index;
//if(n>1)
for(int i=0;i<5-1;i++)
{
int minloc = i;
for(int j=i+1;j<5;j++)
{
if(a[minloc]>a[j])
{
minloc = j;
}
}
swap(a[i],a[minloc]);
}
for(int i=0;i<5;i++)
{
cout<
selection sort c++
void swap(int &a, int &b)
{
int temp = a;
a = b;
b = temp;
}
void Tri_Selection(int tab[],int n)
{
for (int i=0; i tab[j])
swap(tab[i],tab[j]);
}
}
|