This is Hill sorting C program, input plastic array, NUM is the array length, nSTEP is the number of steps, and STEP is the number of steps array:
/* Code written by jgao */
# include & ltstdio.h & gt
# Define nStep 5/* Number of steps */
# define NUM 30/* Number of arrays to be sorted */
void shellSort(int[],int); /* Function */
void printS(int[],int); /* Print array */
Static integer multiple = 0; /* Counter */
int STEP[nStep] = { 15,8,4,2, 1 }; /* Step array */
int main(){
int s[NUM] = {8 13,87,365,62 1,488,90 1,237,55 1,686, 134,
4, 765, 342, 145, 962, 45 1, 288, 552, 682, 34,
88, 552, 98, 532, 88 1, 183, 248, 672, 978, -43}; /* Array to sort */
printf(" Input:\ n ");
Printed matter (number of pieces);
shellSort(s,NUM); /* Sort */
printf(" \ n output:\ n ");
Printed matter (number of pieces);
Returns 0;
}
void shellSort(int s[],int n){
int i,j,k;
for(I = 0; I & ltnsteppi++) {
int STEP = STEP[I];
printf(" \ n ");
for(j = 0; J< step; j ++){
/* Find each array */
printf("%d exchange:(",times++);
for(k = 0; k & lt(int)(n/step); k ++){
int l,m,index = j+k * step;
printf("%d ",index);
If (! K) continue;
for(l = 0; l & ltk; l ++){
int index 2 = j+l * step;
if(s[index]& lt; s[index2])
Break;
}
If (l>= k)
Continue;
Otherwise {
int tmp = s[index];
m = k;
while(m & gt; l){
S[j+m * step ]= s[j+(m- 1)* step];
m-;
};
s[j+l * step]= tmp;
}
}
printf(")\ n ");
Printed matter (s, n);
}
}
}
void printS(int s[],int n){
int I;
for(I = 0; I & ltn;; i ++){
printf("%d ",s[I]);
}
printf(" \ n ");
}
The results of Hill Sorting Program are as follows:
Input:
8 13 87 365 62 1 488 90 1 237 55 1 686 134 4 765 342 145 962 45 1 288 552 682 34 88 552 98 532 88 1 183 248 672 978 -43
0 exchange: (0 15)
45 1 87 365 62 1 488 90 1 237 55 1 686 134 4 765 342 145 962 8 13 288 552 682 34 88 552 98 532 88 1 183 248 672 978 -43
1 exchange: (1 16)
45 1 87 365 62 1 488 90 1 237 55 1 686 134 4 765 342 145 962 8 13 288 552 682 34 88 552 98 532 88 1 183 248 672 978 -43
2 Exchange: (2 17)
45 1 87 365 62 1 488 90 1 237 55 1 686 134 4 765 342 145 962 8 13 288 552 682 34 88 552 98 532 88 1 183 248 672 978 -43
3 Exchange: (3 18)
45 1 87 365 62 1 488 90 1 237 55 1 686 134 4 765 342 145 962 8 13 288 552 682 34 88 552 98 532 88 1 183 248 672 978 -43
4 Exchange: (4 19)
45 1 87 365 62 1 34 90 1 237 55 1 686 134 4 765 342 145 962 8 13 288 552 682 488 88 552 98 532 88 1 183 248 672 978 -43
5 Exchange: (5 20)
45 1 87 365 62 1 34 88 237 55 1 686 134 4 765 342 145 962 8 13 288 552 682 488 90 1 552 98 532 88 1 183 248 672 978 -43
6 Exchange: (6 2 1)
45 1 87 365 62 1 34 88 237 55 1 686 134 4 765 342 145 962 8 13 288 552 682 488 90 1 552 98 532 88 1 183 248 672 978 -43
7 Exchange: (7 22)
45 1 87 365 62 1 34 88 237 98 686 134 4 765 342 145 962 8 13 288 552 682 488 90 1 552 55 1 532 88 1 183 248 672 978 -43
8 Exchange: (8 23)
45 1 87 365 62 1 34 88 237 98 532 134 4 765 342 145 962 8 13 288 552 682 488 90 1 552 55 1 686 88 1 183 248 672 978 -43
9 Exchange: (9 24)
45 1 87 365 62 1 34 88 237 98 532 134 4 765 342 145 962 8 13 288 552 682 488 90 1 552 55 1 686 88 1 183 248 672 978 -43
10 exchange: (10 25)
45 1 87 365 62 1 34 88 237 98 532 134 4 765 342 145 962 8 13 288 552 682 488 90 1 552 55 1 686 88 1 183 248 672 978 -43
1 1 Exchange: (1 1 26)
45 1 87 365 62 1 34 88 237 98 532 134 4 248 342 145 962 8 13 288 552 682 488 90 1 552 55 1 686 88 1 183 765 672 978 -43
12 exchange: (12 27)
45 1 87 365 62 1 34 88 237 98 532 134 4 248 342 145 962 8 13 288 552 682 488 90 1 552 55 1 686 88 1 183 765 672 978 -43
13 exchange: (13 28)
45 1 87 365 62 1 34 88 237 98 532 134 4 248 342 145 962 8 13 288 552 682 488 90 1 552 55 1 686 88 1 183 765 672 978 -43
14 exchange: (14 29)
45 1 87 365 62 1 34 88 237 98 532 134 4 248 342 145 -43 8 13 288 552 682 488 90 1 552 55 1 686 88 1 183 765 672 978 962
15 exchange: (0 8 16)
288 87 365 62 1 34 88 237 98 45 1 134 4 248 342 145 -43 8 13 532 552 682 488 90 1 552 55 1 686 88 1 183 765 672 978 962
16 exchange: (1 9 17)
288 87 365 62 1 34 88 237 98 45 1 134 4 248 342 145 -43 8 13 532 552 682 488 90 1 552 55 1 686 88 1 183 765 672 978 962
17 exchange: (2 10 18)
288 87 4 62 1 34 88 237 98 45 1 134 365 248 342 145 -43 8 13 532 552 682 488 90 1 552 55 1 686 88 1 183 765 672 978 962
18 exchange: (3 1 1 19)
288 87 4 248 34 88 237 98 45 1 134 365 488 342 145 -43 8 13 532 552 682 62 1 90 1 552 55 1 686 88 1 183 765 672 978 962
19 exchange: (4 12 20)
288 87 4 248 34 88 237 98 45 1 134 365 488 342 145 -43 8 13 532 552 682 62 1 90 1 552 55 1 686 88 1 183 765 672 978 962
20 exchange: (5 13 2 1)
288 87 4 248 34 88 237 98 45 1 134 365 488 342 145 -43 8 13 532 552 682 62 1 90 1 552 55 1 686 88 1 183 765 672 978 962
2 1 exchange: (6 14 22)
288 87 4 248 34 88 -43 98 45 1 134 365 488 342 145 237 8 13 532 552 682 62 1 90 1 552 55 1 686 88 1 183 765 672 978 962
22 exchange: (7 15 23)
288 87 4 248 34 88 -43 98 45 1 134 365 488 342 145 237 686 532 552 682 62 1 90 1 552 55 1 8 13 88 1 183 765 672 978 962
23 exchange: (0 4 8 12 16 20 24)
34 87 4 248 288 88 -43 98 342 134 365 488 45 1 145 237 686 532 552 682 62 1 88 1 552 55 1 8 13 90 1 183 765 672 978 962
24 exchange: (15913172125)
34 87 4 248 288 88 -43 98 342 134 365 488 45 1 145 237 686 532 183 682 62 1 88 1 552 55 1 8 13 90 1 552 765 672 978 962
25 exchange: (26101418 22 26)
34 87 -43 248 288 88 4 98 342 134 237 488 45 1 145 365 686 532 183 55 1 62 1 88 1 552 682 8 13 90 1 552 765 672 978 962
26 exchange: (3 7111519 23 27)
34 87 -43 98 288 88 4 248 342 134 237 488 45 1 145 365 62 1 532 183 55 1 672 88 1 552 682 686 90 1 552 765 8 13 978 962
27 exchange: (024681012141618 20 22 24 26 28)
-43 87 4 98 34 88 237 248 288 134 342 488 365 145 45 1 62 1 532 183 55 1 672 682 552 765 686 88 1 552 90 1 8 13 978 962
28 Exchange: (1357911131517192123 25 27 29)
-43 87 4 88 34 98 237 134 288 145 342 183 365 248 45 1 488 532 552 55 1 552 682 62 1 765 672 88 1 686 90 1 8 13 978 962
29 Exchange: (0123456789111122 23 24 25 26.
-43 4 34 87 88 98 134 145 183 237 248 288 342 365 45 1 488 532 55 1 552 552 62 1 672 682 686 765 8 13 88 1 90 1 962 978
Output:
-43 4 34 87 88 98 134 145 183 237 248 288 342 365 45 1 488 532 55 1 552 552 62 1 672 682 686 765 8 13 88 1 90 1 962 978
Press any key to continue.
This is the second: quick sort C program:
/* encoded by jgao, recursively sorted quickly, and input as a character array */
# include & ltstdio.h & gt
void main(){
int quickSort(char vert[],int n,int begin,int end);
char vert[]= " qwertyuiopasdfghjklzxcvbnm ";
int n = 26
Quick sorting (vert, n, 0, n-1);
}
int quickSort(char vert[],int n,int begin,int end){
int print(char* vert,int n,int base);
int front = begin,back = end
char base = vert[front];
if(begin & gt; = end) returns 0;
Otherwise {
Do {
While (back & gt front) {
if(vert[back]& lt; Base) off;
else back-;
};
if(back & gt; front)vert[front ++]= vert[back];
while(front & lt; Back) {
If(vert[front] > base) break;
else front++;
};
if(back & gt; front)vert[back-]= vert[front];
} while(front & lt; Back);
vert[back]= base;
Print (vertical, n, radix);
Quick sort (vert, n, begin, front-1);
Quick sort (vert, n, back+1, end);
Returns1;
}
}
int print(char* vert,int n,int base){
int I;
printf("(%c):\t ",base);
for(I = 0; I & ltn;; i ++){
printf("%c ",vert[I]);
}
printf(" \ n ");
Returns 0;
}
The output results are as follows:
(q): m n e b c l k i o p a j d f g h q s u z x y v t r w
(m): h g e b c l k i f d a j m p o n q s u z x y v t r w
(h): a g e b c d f h i k l j m p o n q s u z x y v t r w
(a)a g e b c d f h I k l j m p o n q s u z x y v t r w
(g): a f e b c d g h i k l j m p o n q s u z x y v t r w
(f)a d e b c f g h I k l j m p o n q s u z x y v t r w
(d): a c b d e f g h i k l j m p o n q s u z x y v t r w
(c)a b c d e f g h I k l j m p o n q s u z x y v t r w
(1) a b c d e f g h i k l j m p o n q s u z x y v t r w
(k): a b c d e f g h i j k l m p o n q s u z x y v t r w
(p): a b c d e f g h i j k l m n o p q s u z x y v t r w
(n): a b c d e f g h i j k l m n o p q s u z x y v t r w
(s): a b c d e f g h i j k l m n o p q r s z x y v t u w
(z): a b c d e f g h i j k l m n o p q r s w x y v t u z
(w): a b c d e f g h i j k l m n o p q r s u t v w y x z
(u): a b c d e f g h i j k l m n o p q r s t u v w y x z
(y): a b c d e f g h i j k l m n o p q r s t u v w x y z
Press any key to continue.