Skip to content

Instantly share code, notes, and snippets.

@rvivek
Created May 7, 2012 01:32
Show Gist options
  • Save rvivek/2625337 to your computer and use it in GitHub Desktop.
Save rvivek/2625337 to your computer and use it in GitHub Desktop.
Insertion sort
#include <iostream>
#define REP(i,N) for ( int i = 0;i < N;i++ )
using namespace std;
int main(){
int N; cin >> N; // size of the array
int * ar = new int [N];
REP(i,N) { cin >> ar[i]; }
REP(i,N)
REP(j,i)
if(ar[i]>ar[j]){
int temp=ar[i]; //swap
ar[i]=ar[j];
ar[j]=temp;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment