24.10.2014 Views

Divide y Vencerás - UPV

Divide y Vencerás - UPV

Divide y Vencerás - UPV

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.

EDA<br />

2004/2005<br />

Problema de la ordenación<br />

public static void insercionDirecta (Object a[]) {<br />

for( int i = 1; i < a.length ; i++ ) {<br />

Comparable elemAInsertar = (Comparable)a[i];<br />

int posIns = i ;<br />

// Busqueda del lugar de insercion ordenada;<br />

// desplazar mientras NO se encuentre<br />

for( ; posIns > 0 && elemAInsertar.compareTo(a[posIns-<br />

1]) < 0 ; posIns--)<br />

}<br />

}<br />

a[posIns] = a[posIns - 1];<br />

a[posIns] = elemAInsertar; // Insercion en posIns<br />

Paolo Rosso Grupos: 2B+ENG - ETSIA

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

Saved successfully!

Ooh no, something went wrong!