Tuesday, January 16, 2018
Monday, January 15, 2018
Thursday, January 11, 2018
Sunday, January 7, 2018
Saturday, April 1, 2017
Sunday, December 11, 2016
hi students
This is high time to study for your Preboard exams. Do share any query here or mail to me at chandni1972@gmail.com. All the best!!
Wednesday, March 25, 2015
Insertion Sort
Here is the code for Insertion Sort.
Best of luck !!
#include <iostream>If you have any doubts, kindly leave them in the comments :)
using namespace std;
void ins_sort(int a[],int n)
{
for(int i = 1; i < n; i++)
{
int key = a[i];
int j = i-1;
while(j>=0 && a[j]>key)
{
a[j+1] = a[j];
j--;
}
a[j+1] = key;
}
}
int main()
{
int n;
cin>>n;
int a[n];
for(int i = 0; i < n; i++)
cin>>a[i];
ins_sort(a,n);
for(int i = 0; i < n; i++)
cout<<a[i]<<" ";
cout<<endl;
return 0;
}
Best of luck !!
Subscribe to:
Posts (Atom)