1 #include <iostream> 2 #include <cstring> 3 using namespace std; 4 void shellsort(int v[],int n) 5 { 6 int gap,i,j,temp; 7 for (gap = n/2 ; gap >0 ; gap /= 2) 8 { 9 for (i = gap; i < n ; ++i) 10 { 11 for (j = i - gap ; j >=0 && v[j] > v[j+gap] ; j -= gap) 12 { 13 temp = v[j]; 14 v[j] = v[j + gap]; 15 v[j+gap] = temp; 16 } 17 } 18 } 19 } 20 //倒置字符串s中各个字符的位置 21 void reverse(char s[]) 22 { 23 int ch; 24 for (int i = 0,j = strlen(s) - 1;i < j ; i++,j-- ) 25 { 26 ch = s[i]; 27 s[i] = s[j]; 28 s[j] = ch; 29 } 30 } 31 //将整数n转换为字符串并保存在s中 32 void itoa(int n ,char s[]) 33 { 34 int i ,sign; 35 if ((sign = n) < 0 ) 36 { 37 n = -n; 38 } 39 i = 0; 40 do 41 { 42 s[i++] = n%10 +'0'; 43 } while (( n = n/10) > 0 ); 44 if (sign < 0 ) 45 { 46 s[i++] = '-'; 47 } 48 s[i] = '