document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #include<iostream.h>
  2. #include<conio.h>
  3. int data[10],data2[10];
  4. int n;
  5.  
  6. void tukar(int a, int b)
  7. {
  8.    int t;
  9.    t=data[b];
  10.    data[b]=data[a];
  11.    data[a]=t;
  12. }
  13. void input()
  14. {
  15.    cout<<"Masukkan jumlah data = ";
  16.    cin>>n;
  17.    for(int i=0;i<n;i++)
  18.    {
  19.       cout<<"Masukkan data ke - "<<(i+1)<<" = " ;
  20.       cin>>data[i];
  21.       data2[i]=data[i];
  22.    }
  23. }
  24.  
  25. void selection_sort()
  26. {
  27.     int pos,i,j;
  28.    for(i=0;i<n-1;i++)
  29.    {
  30.       pos=i;
  31.       for(j=i+1;j<n;j++)
  32.       {
  33.         if(data[j]<data[pos])pos=j;
  34.       }
  35.       if(pos!=i) tukar(pos,i);
  36.    }
  37.    cout<<"selection sort selesai !"<<endl;
  38.    cout<<"Data : "<<endl;
  39.    for(int i=0;i<n;i++)
  40.    {
  41.     cout<<data[i]<<" ";
  42.    }
  43.    cout<<endl;
  44. }
  45. void main()
  46. {
  47.     int pil;
  48.    clrscr();
  49.    do
  50.    {
  51.     cout<<endl;
  52.     cout<<"1. Input Data"<<endl;
  53.     cout<<"2. Selection Sort"<<endl;
  54.     cout<<"3. Exit"<<endl;
  55.         cout<<"Masukkan Pilihan anda = ";
  56.         cin>>pil;
  57.  
  58.     switch(pil)
  59.     {
  60.         case 1: input();break;
  61.         case 2: selection_sort();break;
  62.     }
  63.     getch();
  64.    }
  65.    while(pil!=3);
  66. }
');