06.05.2013 Views

CONTENIDO DE LA LECCIÓN 18

CONTENIDO DE LA LECCIÓN 18

CONTENIDO DE LA LECCIÓN 18

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

MIGUEL Á. TOLEDO MARTÍNEZ<br />

/* El siguiente programa: METSHELL.CPP, utiliza el método Shell para ordenar<br />

un arreglo que contiene 50 elementos generados aleatoriamente.<br />

*/<br />

#include //Para cout y cin<br />

#include //Para rand()<br />

void ordenarShell(int arreglo[], int tamano)<br />

{<br />

int temp, espacio, i, banderaCambio;<br />

Ejemplo <strong>18</strong>.31<br />

espacio = tamano / 2;<br />

do<br />

{<br />

do<br />

{<br />

banderaCambio = 0;<br />

for (i = 0; i < tamano - espacio; i++)<br />

if (arreglo[i] > arreglo[i + espacio])<br />

{<br />

temp = arreglo[i];<br />

arreglo[i] = arreglo[i + espacio];<br />

arreglo[i + espacio] = temp;<br />

banderaCambio = 1;<br />

}//Fin de if<br />

} while (banderaCambio);<br />

} while (espacio = espacio / 2);<br />

}//Fin de ordenarShell()<br />

void main(void)<br />

{<br />

int valores[50], i;<br />

for(i = 0; i < 50; i++)<br />

valores[i] = rand() % 100;<br />

ordenarShell(valores, 50);<br />

for (i= 0; i < 50; i++)<br />

cout

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!