Horje
selection sort c++ algorithm 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++ algorithm
//Selection sort algorithm
selectionSort(array, size)
  repeat (size - 1) times
  set the first unsorted element as the minimum
  for each of the unsorted elements
    if element < currentMinimum
      set element as new minimum
  swap minimum with first unsorted position
end selectionSort




Cpp

Related
what does the modularity mean in c++ Code Example what does the modularity mean in c++ Code Example
how to check sqrt of number is integer c++ Code Example how to check sqrt of number is integer c++ Code Example
max function in c++ Code Example max function in c++ Code Example
delete one specific character in string C++ Code Example delete one specific character in string C++ Code Example
round double to n decimal places c++ Code Example round double to n decimal places c++ Code Example

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