Skip to content

Instantly share code, notes, and snippets.

@jeonghwan-kim
Created October 25, 2013 01:25
Show Gist options
  • Select an option

  • Save jeonghwan-kim/7148081 to your computer and use it in GitHub Desktop.

Select an option

Save jeonghwan-kim/7148081 to your computer and use it in GitHub Desktop.
insert sort
void insert_sort(int a[], int n) {
for (int i=1; i<n; i++) {
int temp = a[i];
// 정렬되어 있는 배열의 경우 루프를 실행하지 않는다.
for (int j=i; j>0 && a[j-1] > a[j]; j--) {
a[j] = a[j-1];
a[j-1] = temp;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment