Bubble Sort

 #include <iostream>

using namespace std;

int main() {

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

    

    int n=10;

    while(n>0){

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

            if(arr[i+1]<arr[i]){

                int temp;

                temp=arr[i];

                arr[i]=arr[i+1];

                arr[i+1]=temp;

            }

            

            

       }

       n--;

    }

    

    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