Selection sort C++

        Selection sort C++


Selection sort C++

#include<bits/stdc++.h>
using namespace std;
int  main()
{
     int a[50],n,i,j;
     cout<< "Enter the size of list : "<<endl;
     cin>>n;
     cout<< "Enter "<<n<< "th array element : "<<endl;
     for(i=0; i<n; i++){
           cin>> a[i];
     }
     for(i=0;i<n-1;i++){
           for(j=i+1; j<n; j++){
                if(a[i] > a[j])
                {
                   swap(a[j],a[i]);
                 }
           }
     }
     cout<< "Arranged list is : "<<endl;
     for(i=0; i<n; i++){
           cout <<a[i]<<" ";
     }

}

Comments

Popular posts from this blog

Kruskal’s algorithm C++

Menu C++

Recursion C++