Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

C - Insertion Sort

DZone's Guide to

C - Insertion Sort

· ·
Free Resource
Classic implementation of the Insertion Sort algorithm.


void isort_c(unsigned *a, int n) {
  int k;
  for (k = 1; k < n; ++k) {
    int key = a[k];
    int i = k - 1;
    while ((i >= 0) && (key < a[i])) {
      a[i + 1] = a[i];
      --i;
    }
    a[i + 1] = key;
  }
}
Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}