/*  Funzione che ricerca il minimo ed il massimo in un vettore di interi
    con un numero di elementi pari, effettuando un numero di confronti
    inferiore a quelli richiesti da una scansione sequenziale.
*/

void cercaMaxMin (int a[], ind dim) {

    int min, max, i;

    if (a[0] > a[1]) {
        max = a[0];
        min = a[1];
    }
    else {
        min = a[0];
        max = a[1];
    }

    for (i = 2; i<dim; i += 2)
        if (a[i] > a[i+1]) {
            if (a[i] > max) max = a[i];
            if (a[i+1] < min) min = a[i+1];
        }
        else {
            if (a[i+1] > max) max = a[i+1];
            if (a[i] < min) min = a[i];
        }
    printf("minimo=%d\n",min);
    printf("massimo=%d\n",max);
}

-- ArcangeloTripi - 18 Nov 2002

Edit | Attach | Watch | Print version | History: r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r3 - 2003-10-04 - AndreaSterbini






 
Questo sito usa cookies, usandolo ne accettate la presenza. (CookiePolicy)
Torna al Dipartimento di Informatica
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback