Skip to main content

Selection Sort Implementation

*
#include<iostream> using namespace std; int main() { int n; cout<<"Enter the size of array : "<<endl; cin>>n; int array[n]; cout<<"Enter elements : "<<endl; for(int a=0;a<n;a++) { cin>>array[a]; } cout<<"Starting selection sort : "<<endl; for(int i=0;i<n;i++) { int min_index=i; for(int j=i+1;j<n;j++) { if(array[min_index]>array[j]) { min_index=j; } } if (min_index != i) { int temporary; temporary=array[min_index]; array[min_index]=array[i]; array[i]=temporary; } } for(int k=0;k<n;k++) { cout<<array[k]<<endl; } return 0; }

Quote:

Go as far as you can see; when you get there,you'll be able to see farther...