Horje
c++ code for selection sort Code Example
c++ code for selection sort
#include<bits/stdc++.h>
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<<a[i]<<" ";
    }
    return 0;
}
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<n; i++)
    {
        for (int j=i+1; j<n; j++)
            if (tab[i] > tab[j])
                swap(tab[i],tab[j]);
    }
}




Cpp

Related
c++ print vector without loop Code Example c++ print vector without loop Code Example
login system with c++ Code Example login system with c++ Code Example
c++ display numbers as binary Code Example c++ display numbers as binary Code Example
check if double is integer c++ Code Example check if double is integer c++ Code Example
std string to const char * c++ Code Example std string to const char * c++ Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
9