C Tutorial/Search Sort/Shell Sort — различия между версиями


Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/includes/exception/MWExceptionHandler.php on line 179

Deprecated: Creation of dynamic property PPDStack::$accum is deprecated in /var/www/cppe.ru/www/includes/parser/Preprocessor_DOM.php on line 803

Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/includes/exception/MWExceptionHandler.php on line 179

Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/vendor/mediawiki/at-ease/src/Functions.php on line 48
Материал из C\C++ эксперт
Перейти к: навигация, поиск
м (1 версия: Импорт контента...)
 
(нет различий)

Версия 14:21, 25 мая 2010

The Shell Sort

#include <string.h>
  #include <stdio.h>
  #include <stdlib.h>
  void shell(char *items, int count)
  {
    register int i, j, gap, k;
    char x, a[5];
    a[0]=9; a[1]=5; a[2]=3; a[3]=2; a[4]=1;
    for(k=0; k < 5; k++) {
      gap = a[k];
      for(i=gap; i < count; ++i) {
        x = items[i];
        for(j=i-gap; (x < items[j]) && (j >= 0); j=j-gap)
          items[j+gap] = items[j];
        items[j+gap] = x;
      }
    }
  }
  int main(void)
  {
    char s[255];
    printf("Enter a string:");
    gets(s);
    shell(s, strlen(s));
    printf("The sorted string is: %s.\n", s);
    return 0;
  }
Enter a string:3
The sorted string is: 3.