Insertion Sort

 #include <iostream>

using namespace std;

int main() {

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

    int temp;

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

        temp=arr[i];

        for(int j=i-1;j>=0;j--){

                if(arr[j]>temp){

                     

                    arr[j+1]=arr[j];

                }

                arr[j]=temp;

            }

        }

    

    

    

    

    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