/*
** Would you please run this program
** and let me know what the output is?
** I'm of the opinion that the QSORT function
** which is currently in listgen.c, at
**
http://code.google.com/p/ccl/downloads/detail?name=ccl.zip&can=2&q=
** has approximately zero chance of correctly sorting
** a data set of as many as 10000000 psuedorandom keys.
*/
#include<stdlib.h>
#include "containers.h"
#include "intlist.h"
#define N 10000000
int
main(void)
{
intList *L1;
size_t i;
int d;
long unsigned sum=0,newSum=0;
Iterator *it;
int *pint, last_pint;
L1 = iintList.Create(sizeof(int));
iintList.UseHeap(L1,NULL); // Use specialized Heap
// Add N random numbers to the integer list
for (i=0; i<N;i++) {
d = rand();
sum += d;
iintList.Add(L1,d);
}
// Sort it
iintList.Sort(L1);
// Go through the sorted list using an iterator
it = iintList.NewIterator(L1);
i=0;
pint = it->GetFirst(it);
while (pint != NULL) {
last_pint = *pint;
newSum += last_pint;
pint = it->GetNext(it);
if (pint != NULL&& last_pint> *pint) {
puts("\n\nThe data is not sorted.\n\n");
iintList.Finalize(L1);
exit(EXIT_SUCCESS);
}
}
// Verify that both sums are identical
if (sum != newSum) {
printf("Failed\n");
} else {
printf("Sum = %lu\n",sum);
}
// Destroy the list
iintList.Finalize(L1);
return 0;
}