daily pastebin goal
21%
SHARE
TWEET

Untitled

a guest Jan 21st, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2. using namespace std;
  3. void insertionsort(int a[], int N)
  4. {
  5.     for(int i=0;i<N;i++)
  6.     {
  7.         int j=i-1;int key=a[i];
  8.         while(j>=0 && a[j]>key)
  9.         {
  10.             a[j+1]=a[j];
  11.             j--;
  12.         }
  13.         j++;
  14.         a[j]=key;
  15.     }
  16. }
  17. int main()
  18. {
  19.     int arr[]={5,2,1,4};
  20.     int N=sizeof(arr)/sizeof(int);
  21.     insertionsort(arr,N);
  22.     for(int i=0; i<N; i++)
  23.     {
  24.         cout<<arr[i]<<endl;
  25.     }
  26. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top