selection sort with steps code example

Example 1: selection sort

#include 

using namespace std; 

void selectionSort(int arr[], int n){
    int i,j,min;
    
    for(i=0;i

Example 2: selection sort

procedure selection sort 
   list  : array of items
   n     : size of list

   for i = 1 to n - 1
   /* set current element as minimum*/
      min = i    
  
      /* check the element to be minimum */

      for j = i+1 to n 
         if list[j] < list[min] then
            min = j;
         end if
      end for

      /* swap the minimum element with the current element*/
      if indexMin != i  then
         swap list[min] and list[i]
      end if
   end for
	
end procedure

Tags:

Misc Example