iseqai

Untitled

Sep 24th, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     int i,j,n,temp;
  7.     n =10;
  8.    int a[]={90,145,67,23,189,29,334,92, 266, 95};
  9.    cout<<"\n Data angka sebelum diurutkan"<<endl;
  10.     for(i=0;i<n;i++)
  11.     {
  12.         cout<<a[i]<<" , ";
  13.        
  14.     }
  15.  
  16.     for(i=1;i<=n-1;i++)
  17.     {
  18.         temp=a[i];
  19.         j=i-1;
  20.  
  21.         while((temp<a[j])&&(j>=0))
  22.         {
  23.             a[j+1]=a[j];    
  24.             j=j-1;
  25.         }
  26.  
  27.         a[j+1]=temp;    //insert element in proper place
  28.        
  29.     }
  30.  
  31.     cout<<"\n \n urut setelah inserting sort\n";
  32.     for(i=0;i<n;i++)
  33.     {
  34.         cout<<a[i]<<" , ";
  35.     }
  36.  
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment