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

main(int argc, char** argv)
// run as "a.out 100 25 11", where 100 is the size to be tested,
// and 25 is the range of entries, and 11 is the seed
{
  int *array, *index; int comp, i, size, mod, seed;

  if (argc < 4) {cerr << "Call as \"" << argv[0] << " <size> <mod> <seed>\"" << endl;
                 exit(1);};
  sscanf(argv[1], "%d", &size);
  sscanf(argv[2], "%d", &mod);
  array = new int[size];
  index = new int[size];

  sscanf(argv[3],"%d",&seed);
  srandom(seed); //initialize the random generator;
  cout << "Input array" << endl;
  for(i = 0; i < size; i++) {array[i] = random() % mod; cout << array[i] << " ";};
  cout << endl;

  comp = indir_insort(array, size, index);
  cout << "Indirect insertion sort: Sorted array after "<< comp <<" comparisons" << endl;
  for(i = 0; i < size; i++) cout << array[index[i]] << " "; cout << endl;
  
  comp = insort(array, size);
  cout << "Insertion sort: Sorted array after " << comp << " comparisons" << endl;
  for(i = 0; i < size; i++) cout << array[i] << " "; cout << endl;
}
