TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: DAVID NOON
from: GEORGE WHITE
date: 1998-04-09 22:08:00
subject: Multiple Key sorts 2/

>>> Continued from previous message
/* Re-initialise data to sort for next test */
    memcpy (sort_strct,ref_strct,sort_len * sizeof (ref_strct[0]));
    ssort (sort_strct,sort_len,sizeof (sort_strct[0]),compare_key);
    ssort (sort_strct,sort_len,sizeof (sort_strct[0]),compare_index);
    printf (" %4d seq",check_data (sort_len));
    if (redir)
        {
        show_diff (sort_len);
        printf ("\nInsertion Sort");
        }
    else
        printf (" Insertion Sort");
/* Re-initialise data to sort for next test */
    memcpy (sort_strct,ref_strct,sort_len * sizeof (ref_strct[0]));
    isort (sort_strct,sort_len,sizeof (sort_strct[0]),compare_key);
    isort (sort_strct,sort_len,sizeof (sort_strct[0]),compare_index);
    printf (" %4d seq",check_data (sort_len));
    if (redir)
        show_diff (sort_len);
    }
while ((sort_len /= 2) > TEST_END);
time (&curr_time);
if (redir)
    printf ("\n\nRun Completed: %s",ctime (&curr_time));
else
    printf ("\nRun Complete\n");
return 0;
}
void show_diff (int sort_len)
{
int counter;
for (counter = 1;counter < sort_len;counter++)
    {
    if (sort_strct[counter - 1].index > sort_strct[counter].index)
        {
        printf ("\nIndex variation at %5d",counter);
        printf ("Data %4d, %4d, %4d",sort_strct[counter-1].index,
                                        sort_strct[counter-1].key,
                                        sort_strct[counter-1].sequence);
        printf ("Data %4d, %4d, %4d",sort_strct[counter].index,
                                        sort_strct[counter].key,
                                        sort_strct[counter].sequence);
        }
    else
    if (sort_strct[counter - 1].index == sort_strct[counter].index)
        {
        if (sort_strct[counter-1].key > sort_strct[counter].key)
            {
            printf ("\nKey variation at %5d",counter - 1);
            printf (" Data %4d, %4d, %4d",sort_strct[counter-1].index,
                                        sort_strct[counter-1].key,
                                        sort_strct[counter-1].sequence);
            printf (" Next %4d, %4d, %4d",sort_strct[counter].index,
                                        sort_strct[counter].key,
                                        sort_strct[counter].sequence);
            }
        else
        if (sort_strct[counter-1].key == sort_strct[counter].key)
            if (sort_strct[counter-1].sequence > 
ort_strct[counter].sequence)
                {
                printf ("\nSequence variation at %5d",counter-1);
                printf (" Data %4d, %4d, %4d",sort_strct[counter-1].index,
                                        sort_strct[counter-1].key,
                                        sort_strct[counter-1].sequence);
                printf (" Next %4d, %4d, %4d",sort_strct[counter].index,
                                        sort_strct[counter].key,
                                        sort_strct[counter].sequence);
                }
        }
    }
}
int check_data (int sort_len)
{
int counter,err_count = 0;;
for (counter = 1;counter < sort_len;counter++)
    {
    if (sort_strct[counter - 1].index > sort_strct[counter].index)
        err_count++;
    else
    if (sort_strct[counter - 1].index == sort_strct[counter].index)
        {
        if (sort_strct[counter-1].key > sort_strct[counter].key)
            err_count++;
        else
        if (sort_strct[counter-1].key == sort_strct[counter].key)
            if (sort_strct[counter-1].sequence > 
ort_strct[counter].sequence)
                err_count++;
        }
    }
return err_count;
}
int     compare_key (const void *a,const void *b)
{
return ((struct  test_struct *) a)->key - ((struct  test_struct *) b)->key;
}
int     compare_index (const void *a,const void *b)
{
return ((struct  test_struct *) a)->index - ((struct  test_struct *) 
b)->index;
}
George
 * SLMR 2.1a * Wastebasket: Something to throw things near.
--- Maximus/2 3.01
---------------
* Origin: DoNoR/2,Woking UK (44-1483-717905) (2:440/4)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.