17.05.2013 Views

Tutorial de Apuntadores y Arreglos en C - Cimat

Tutorial de Apuntadores y Arreglos en C - Cimat

Tutorial de Apuntadores y Arreglos en C - Cimat

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

void bubble(int *p, int N);<br />

int compare(void *m, void *n);<br />

int main(void)<br />

{<br />

int i;<br />

putchar('\n');<br />

}<br />

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

{<br />

printf("%d ", arr[i]);<br />

}<br />

bubble(arr,10);<br />

putchar('\n');<br />

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

{<br />

printf("%d ", arr[i]);<br />

}<br />

return 0;<br />

void bubble(int *p, int N)<br />

{<br />

int i, j, t;<br />

for (i = N-1; i >= 0; i--)<br />

{<br />

for (j = 1; j *n1);<br />

}<br />

Observa que, al hacer esto, <strong>en</strong> compare() tuvimos que introducir la conversión <strong>de</strong>l puntero void pasado, al tipo<br />

<strong>de</strong> datos que realm<strong>en</strong>te se está or<strong>de</strong>nando. Pero, como veremos más tar<strong>de</strong>, eso está bi<strong>en</strong>. Y ya que lo que se<br />

está pasando a bubble() es aún un puntero a un arreglo <strong>de</strong> <strong>en</strong>teros, tuvimos que convertir esos punteros a<br />

punteros sin tipo cuando los pasamos como parámetros <strong>en</strong> nuestra llamada a la función compare().<br />

42

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

Saved successfully!

Ooh no, something went wrong!