Advertisement
Md_hosen_zisad

insertion ques b

Nov 5th, 2018
480
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. int a[100];
  4. int insertion(int a[],int n){
  5.     int item,j;
  6.     for(int i=1;i<n;i++){
  7.         item=a[i];
  8.         j=i-1;
  9.         while(j>=0 && a[j]<item){
  10.             a[j+1]=a[j];
  11.             j=j-1;
  12.         }
  13.         a[j+1]=item;
  14.     }
  15.  
  16. }
  17.  
  18. int main(){
  19.     int n;
  20.     cin>>n;
  21.     for(int i=0;i<n;i++){
  22.         cin>>a[i];
  23.     }
  24.  
  25.     insertion(a,n);
  26.     for(int i=0;i<n;i++){
  27.         cout<<a[i]<<"\t";
  28.     }
  29.     cout<<"\n";
  30.  
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement