Skip to main content

selection sort

#include <iostream.h>
#include <conio.h>
#define n 5

void main()
{
 int A[n]={15,10,7,25,8};
 int temp,i,j,k;

 cout<<"Data sebelum diurutkan : "<<endl;
 for(i=0;i<=n-1;i++)
 {
     cout<<A[i]<<" ";
 }
 for(k=0;k<=n-2;k++)
 {
     j=k;

   for(i=k+1;i<=n-1;i++)
   {
       if(A[j]>A[i])
       {
           j = i;
       }
     }
  temp=A[j];
   A[j]=A[k];
   A[k]=temp;
 }
 cout<<endl<<endl;
 cout<<"Data setelah diurutkan : "<<endl;
 for(i=0;i<=n-1;i++)
 {
     cout<<A[i]<<" "<<endl;
 }

getch();
}

Comments