C Insertion Sort

Insertion Sort


#include <string.h>
#include <stdio.h>
#include <stdlib.h>
/*from  www.j a  v  a 2  s. co  m*/

void insert(char *items, int count) {

  register int i, b;
  char t;

  for(i=1; i < count; ++i) {
    t = items[i];
    for(b=i-1; (b >= 0) && (t < items[b]); b--)
      items[b+1] = items[b];
    items[b] = t;
  }
}

int main(void)
{
  char s[255] = "asdfasdfasdfadsfadsf";
  insert(s, strlen(s));
  printf("The sorted string is: %s.\n", s);

  return 0;
}




















Home »
  C Language »
    Data Structures »




Data Structure
Algorithms