>>> 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)
|