// File: Sorting/testisort.C
#include <stdio.h>  // for sscanf
#include <iostream.h>
extern "C" long random(void);
extern "C" void srandom(int);
extern insort(int[], int);

main(int argc, char** argv)
// run as "a.out 100 25", where 100 is the size to be tested,
// and 25 is the range of entries
{int *array; int comp, i, size, mod;
 srandom(101); // seed random number generator
 if (argc < 3) {cerr << "Call as \"" << argv[0] << " <size> <mod>\"" << endl;
                exit(1);};
 sscanf(argv[1], "%d", &size); sscanf(argv[2], "%d", &mod);
 array = new int[size];
 cout << "Input array" << endl;
 for(i = 0; i < size; i++) {array[i] = random() % mod; cout << array[i] << " ";};
 cout << endl;
 comp = insort(array, size);
 cout << "Sorted array after " << comp << " comparisons" << endl;
 for(i = 0; i < size; i++) cout << array[i] << " "; cout << endl;
}
