Interpolation search: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
m Bot: parametri del template:Algoritmo in italiano |
m →Esempio di implementazione: tag source deprecati, replaced: <source lang= → <syntaxhighlight lang=, </source> → </syntaxhighlight> |
||
Riga 21:
Il seguente codice [[C++]] è un esempio di semplice implementazione. Ad ogni passo calcola una possibile posizione del valore, per poi restringere l'intervallo —come nella ricerca binaria— aumentando il lower bound o diminuendo l'upper bound.
<
template <typename T>
int interpolation_search(T arr[], int size, T key)
Riga 44:
return -1;
}
</syntaxhighlight>
<!-- Notice that having probed the list at index ''mid'', for reasons of loop control administration, this code sets either ''high'' or ''low'' to be not ''mid'' but an adjacent index, which ___location is then probed during the next iteration. Since an adjacent entry's value will not be much different the interpolation calculation is not much improved by this one step adjustment, at the cost of an additional reference to distant memory such as disc.
|