C/Data Structure Algorithm/Insertion Sort

Материал из C\C++ эксперт
Перейти к: навигация, поиск

The Insertion Sort

<source lang="cpp">

  1. include <string.h>
  2. include <stdio.h>
  3. include <stdlib.h>

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+1] = t;
   items[b] = t;
 }

} int main(void) {

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

}


      </source>