Created
May 7, 2012 01:32
-
-
Save rvivek/2625337 to your computer and use it in GitHub Desktop.
Insertion sort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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