Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #include<iostream.h>
  2. #include<conio.h>
  3. int data[10];
  4. int n;
  5.  
  6. //Created by Krisna Anggara
  7. void tukar(int a, int b)
  8. {
  9.     int t;
  10.    t=data[b];
  11.    data[b]=data[a];
  12.    data[a]=t;
  13. }
  14.  
  15. void asc()
  16. {
  17.     int pos,i,j;
  18.    for(i=0;i<n-1;i++)
  19.    {
  20.     pos=i;
  21.       for(j=i+1;j<n;j++)
  22.       {
  23.         if(data[j]<data[pos])pos=j;
  24.       }
  25.       if(pos!=i) tukar(pos,i);
  26.    }
  27.    cout<<"Ascending sort selesai !"<<endl;
  28.    cout<<"Data : "<<endl;
  29.    for(int i=0;i<n;i++)
  30.    {
  31.     cout<<data[i]<<" ";
  32.    }
  33.    cout<<endl;
  34. }
  35.  
  36. void desc()
  37. {
  38.     int pos,i,j;
  39.    for(i=0;i<n-1;i++)
  40.    {
  41.     pos=i;
  42.       for(j=i+1;j<n;j++)
  43.       {
  44.         if(data[j]>data[pos])pos=j;
  45.       }
  46.       if(pos!=i) tukar(pos,i);
  47.    }
  48.    cout<<"Descending sort selesai !"<<endl;
  49.    cout<<"Data : "<<endl;
  50.    for(int i=0;i<n;i++)
  51.    {
  52.     cout<<data[i]<<" ";
  53.    }
  54.    cout<<endl;
  55. }
  56.  
  57.  
  58. void input()
  59. {
  60.     cout<<"Masukkan jumlah data = ";
  61.    cin>>n;
  62.    for(int i=0;i<n;i++)
  63.    {
  64.     cout<<"Masukkan data ke - "<<(i+1)<<" = " ;
  65.       cin>>data[i];
  66.    }
  67. }
  68.  
  69.  
  70. void main()
  71. {
  72.     int pil;
  73.    clrscr();
  74.    do
  75.    {
  76.       clrscr();
  77.     cout<<"1. Input Data"<<endl;
  78.     cout<<"2. Urutkan"<<endl;
  79.     cout<<"3. Exit"<<endl;
  80.       cout<<"Masukkan Pilihan anda = ";
  81.       cin>>pil;
  82.  
  83.     switch(pil)
  84.     {
  85.         case 1: input();break;
  86.         case 2:
  87.          asc();
  88.          desc();
  89.          break;
  90.  
  91.     }
  92.     getch();
  93.    }
  94.    while(pil!=3);
  95. }