Red de conocimientos sobre prescripción popular - Conocimiento del confinamiento - Escriba un programa completo en lenguaje C, que incluya clasificación Hill y clasificación rápida.

Escriba un programa completo en lenguaje C, que incluya clasificación Hill y clasificación rápida.

He depurado ambos programas y no hay ningún problema.

Este es un programa C de clasificación Hill, ingresa una matriz plástica, NUM es la longitud de la matriz, nSTEP es el número de pasos, STEP es la matriz de pasos:

/* código escrito por jgao*/

# include & ltstdio.h & gt

#Define nStep 5/*Número de pasos*/

# define NUM 30/* Número de matrices a ordenar* /

void shellSort(int[], int); /*function*/

void printS(int[], int); matriz*/

Múltiplo entero estático = 0; /*Contador*/

int PASO[nPaso] = {15, 8, 4, 2, 1}; */

int main(){

int s[NUM] = {813, 87, 365, 621, 488, 901, 237, 551, 686, 134,

4 , 765, 342, 145, 962, 451, 288, 552, 682, 34,

88, 552, 98, 532, 881, 183, 248, 672, 978, -43};/* Matriz a ordenar*/

printf(" Entrada:\ n ");

Impresiones (número de piezas);

shellSort(s, NUM);/ *Sort*/

printf(" \ n salida:\ n ");

Material impreso (número de piezas

);

Devuelve 0;

}

void shellSort(int s[], int n){

int i, j, k; >

for(I = 0; i & ltnStepi ++){

int PASO = PASO[I];

printf(" \ n ");

for(j = 0; j & ltstep;j++){

/*Encontrar cada matriz*/

printf("%d exchange:(", times++) ;

for(k = 0;k & lt(int)(n/paso);k++){

int l, m, index = j+k * paso;

printf("%d ", index);

Si (!k) continúa;

for(l = 0; l & ltk; l ++ ) {

int index 2 = j+l * paso;

if(s[index]<s[index2])

Descanso;

}

Si (l & gt= k)

Continuar;

De lo contrario {

int tmp = s [índice];

m = k;

mientras(m & gt; l){

s[j+m *paso]= s[j+ (m-1 )*paso];

m-;

};

s[j+l * paso]= tmp;

}

}

printf()\ n ");

Imprimir(s, n);

}

}

}

void printS(int s[], int n){

int I;

for( I = 0;i<n;i++){

printf("%d ",s[I]);

}

printf( "\n");<

/p>

}

Los resultados del programa de clasificación Hill son los siguientes:

Entrada:

813 87 365 621 488 901 237 551 686 134 4 765 342 145 962 451 288 552 682 34 88 552 98 532 881 183 248 672 978 -43

0Intercambio: (0 15)

451 87 365 621 488 901 7 551 686 134 4 765 342 145 962 813 288 552 682 34 88 552 98 532 881 183 248 672 978 -43

1Intercambio: (1 16)

451 87 365 621 488 1 237 5 51 686 134 4 765 342 145 962 813 288 552 682 34 88 552 98 532 881 183 248 672 978 -43

2Intercambio: (2 17)

451 87 365 621 88 901 237 551 686 134 4 765 342 145 962 813 288 552 682 34 88 552 98 532 881 183 248 672 978 -43

3Intercambio: (3 18)

451 87 5 621 488 901 237 551 686 134 4 765 342 145 962 813 288 552 682 34 88 552 98 532 881 183 248 672 978 -43

4Intercambio: (4 19)

451 87 365 621 34 901 237 551 686 134 4 765 342 145 962 813 288 552 682 488 88 552 98 532 881 183 248 672 978 -43

5 intercambio:( 5 20)

451 87 365 621 34 88 237 551 686 134 4 765 342 145 962 813 288 552 682 488 901 552 98 532 881 183 248 672 978 -43

6 Intercambio :(6 21)

451 87 365 621 34 88 237 551 686 134 4 765 342 145 962 813 288 552 682 488 901 552 98 532 881 183 248 672 978 -43

7 intercambio: 7 22)

451 87 365 621 34 88 237 98 686 134 4 765 342 145 962 813 288 552 682 488 901 552 551 532 881 183 248 672 978 -43

8 intercambio: (8 23)

451 87 365 621 34 88 237 98 532 134 4 765 342 145 962 813 288 552 682 488 901 552 551 686 881 183 248 672 978 -43

9Ex cambio: (9 24)

451 87 365 621 34 88 237 98 532 134 4 765 342 145 962 813 288 552 682 488 901 552 55

1 686 881 183 248 672 978 -43

10 intercambio: (10 25)

451 87 365 621 34 88 237 98 532 134 4 765 342 145 962 813 288 552 682 4 88 901 552 551 686 881 183 248 672 978 -43

11Intercambio: (11 26)

451 87 365 621 34 88 237 98 532 134 4 248 342 145 962 813 88 552 682 488 901 552 551 686 881 183 765 672 978 -43

12Intercambio: (12 27)

451 87 365 621 34 88 237 98 532 134 4 248 342 145 962 813 288 552 682 488 901 552 551 686 881 183 765 672 978 -43

13Intercambio: (13 28)

451 87 365 621 34 88 237 98 532 134 4 248 342 145 962 813 288 552 682 488 901 552 551 686 881 183 765 672 978 -43

14Intercambio: (14 29)

451 87 365 621 34 88 237 98 532 134 4 248 342 145 - 43 813 288 552 682 488 901 552 551 686 881 183 765 672 978 962

15Intercambio: (0 8 16)

288 87 365 621 34 88 237 98 451 134 248 342 145 -43 813 532 552 682 488 901 552 551 686 881 183 765 672 978 962

16Intercambio: (1 9 17)

288 87 365 621 34 88 237 98 451 34 4 248 342 145 -43 813 532 552 682 488 901 552 551 686 881 183 765 672 978 962

17Intercambio: (2 10 18)

288 87 4 621 34 88 237 8 451 134 365 248 342 145 -43 813 532 552 682 488 901 552 551 686 881 183 765 672 978 962

18 intercambio: (3 11 19)

288 87 4 248 88 237 98 451 134 365 488 342 145 -43 813 532 552 682 621 901 552 551 686 881 183 765 672 978 962

19Intercambio: (4 12 20)

288 87 4 248 34 88 237 98 451 134 365 488 342 145 -43 813 532 552 682 621 901 552 551 686 881 183 765 672 978 962

20 Intercambio:(5 13 21)

288 87 4 248 34 88 237 98 451 134 365 488 342

145-43 813 532 552 682 621 901 552 551 686 881 183 765 672 978 962

21Exchange: (6 14 22)

288 87 4 248 34 88-43 98 451 134 365 488 342 145 237 813 532 552 682 621 901 552 551 686 881 183 765 672 978 962

22Intercambio: (7 15 23)

288 87 4 248 3 88 - 43 98 451 134 365 488 342 145 237 686 532 552 682 621 901 552 551 813 881 183 765 672 978 962

23Intercambio: (0 4 8 12 16 20 24)

34 87 4 248 288 88 -43 98 342 134 365 488 451 145 237 686 532 552 682 621 881 552 551 813 901 183 765 672 978 962

24Intercambio: (1 5 13 17 21 25)

>

34 87 4 248 288 88 -43 98 342 134 365 488 451 145 237 686 532 183 682 621 881 552 551 813 901 552 765 672 978 962

25 Intercambio:(2 6 10 14 18 22 26)

34 87 -43 248 288 88 4 98 342 134 237 488 451 145 365 686 532 183 551 621 881 552 682 813 901 552 76 5 672 978 62

26 Intercambio: (3 7 11 15 19 23 27)

34 87 -43 98 288 88 4 248 342 134 237 488 451 145 365 621 532 183 551 672 881 552 682 686 90 55 2 765 813 978 962

27 intercambio: (0 2 4 6 8 10 12 14 16 18 20 22 24 26 28)

-43 87 4 98 34 88 237 248 288 134 342 488 365 145 451 621 532 183 551 672 682 552 765 686 881 552 901 813 978 962

28Intercambio: (1 3 5 7 9 1 1 1 3 1 5 1 7 1 9 21 23 25 27 29 )

-43 87 4 88 34 98 237 134 288 145 342 183 365 248 451 488 532 552 551 552 682 621 765 672 881 686 901 813 978 962

29 Intercambio:(0 1 2 3 4 5 6 7 8 9 1 1 1 1 22 23 24 25 26

-43 4 34 87 88 98 134 145 183 237 248 288 342 365 451 488 532 551 552 552 621 672 682 86 765 813 881 901 962 978

Salida:

-

43 4 34 87 88 98 134 145 183 237 248 288 342 365 451 488 532 551 552 552 621 672 682 686 765 813 881 901 962 978 Pulsa cualquier tecla para continuar

Esto es segundo: programa C de clasificación rápida:

/*Codificado por jgao, clasificación rápida recursiva, entrada como matriz de caracteres*/

# include & ltstdio.h & gt

void main(){

int quickSort(char vert[], int n, int start, int end);

char vert[]= " qwertyuiopasdfghjklzxcvbnm "; /p>

int n = 26

QuickSort(vert, n, 0, n-1);

}

int quickSort( char vert); [], int n, int comenzar, int fin){

int print(char* vert, int n, int base);

int frente = comenzar, atrás = terminar

char base = vert[front];

si (begin & gt; = end) devuelve 0;

de lo contrario{

hacer {

mientras(atrás>front){

if(vert[atrás]<base) apagado;

si no atrás-;

};

if(atrás & gt; frente)vert[frente++]= vert[atrás];

mientras(frente & lt;atrás) {

if(vert[front]>base) off;

else front++;

};

if(back & gt ;front)vert[back-] = vert[frente];

} while(front & lt;back);

vert[back]= base;

print(vert, n, base

quicksort(vert, n, comenzar, frente-1

quicksort(vert, n, back + 1, end

); Devuelve 1;

}

}

int print(char* vert, int n, int base){

int I;

printf("(%c):\t ",base);

for(I = 0;i<n;i ++){

printf ("%c ",vert[I]);

}

printf(" \ n ");

Devuelve 0;

}

Los resultados de salida son los siguientes:

(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): edad b c d f h i k l j m p o n q s u z x y v t r w

(a)edad 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 tu 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

Presiona cualquier tecla para continuar