HeapSort - porównania i zamiany

0

Witam. mam ogromną prośbę: mógłby mi ktoś w poniższym kodzie zaznaczyć gdzie należy zliczać porównania i zamiany??
z góry dzięki;)

void makeheap (int n)
{
    int i, val, s, f ;
    for ( i = 1 ; i < n ; i++ )
    {
        val = table[i] ;
        s = i ;
        f = (s-1)/2 ;
        while ( s > 0 && table[f] < val )
        {
            table[s] = table[f] ;
            s = f ;
            f = ( s - 1 ) / 2 ;
        }
        table[s] = val ;
    }
}//makeheap

void heapsort_core (int n)
{
    int i, s, f, ivalue ;
    for ( i = n - 1 ; i > 0 ; i-- )
    {
        ivalue = table[i] ;
        table[i] = table[0] ;
        f = 0 ;

        if ( i == 1 ) s = -1 ;
        else s = 1 ;
        if ( i > 2 && table[2] > table[1] ) s = 2 ;


        while ( s>=0 && ivalue<table[s])
        {
            table[f] = table[s] ;
            f = s ;
            s = 2 * f + 1 ;

            if ( s + 1 <= i - 1 && table[s] < table[s + 1] ) s++ ;
            if ( s > i - 1 ) s = -1 ;
        }
        table[f] = ivalue ;
    }
}//heapsort

void heapsort_main(int size)
{
    makeheap(size);
    printf("\n\nPo utworzeniu kopca:\n");
    print_table(1,1,1,size);
    heapsort_core(size);
    print_table(1,1,1,size);
}
 
0

Porównania proponuję tam gdzie coś porównujesz, a zamiany tam gdzie zamieniasz :)

1 użytkowników online, w tym zalogowanych: 0, gości: 1