Selection_sort

 #include <iostream>

using namespace std;

int main() {

    int arr[10]={9,8,7,6,5,4,3,2,1,0};

    

    int start_arr=0;

    while(start_arr<10){

        int i=start_arr;

        int min=100,min_index;

        for(;i<10;i++){

            if(arr[i]<min){

                min=arr[i];//min value for start_arr to end

                min_index=i;

            }

        }

        

        int temp;

        temp=arr[start_arr];

        arr[start_arr]=min;

        arr[min_index]=temp;

        start_arr++;

    }

    for (int i=0;i<10;i++){

        cout<<arr[i]<<" ";

    }

    

    return 0;

}

Comments

Popular posts from this blog

Sum of Even Numbers till N

Find the Runner-Up Score!

Print All Substrings