/********************************************************************************************
sorttool.cpp
Jim Millard
for CO311
Sorting utility routines
********************************************************************************************/
#include <iostream>
#include <string>
#include <time.h> //for seeding the random number generator
#include "sorttool.h"
using namespace std;
//this routine fills the array in Arg1 with the smaller of the Arg2 and Arg3.
//Arg2 is used for error control, so we don't go beyond the full array.
void FillWithRand(int Array[], const int maxsize, const int count)
{
time_t t;
srand((unsigned) time(&t));
for (int i = 0; (i < count) && (i < maxsize); i++)
{
//generate the new number
int newNumber = rand() % 10000;
//check for duplicates (we don't want any)
bool found = false;
for (int j = 0; (j < count) && (j < maxsize); j++)
if (Array[j] == newNumber)
found = true;
//if there were no duplicates, save the number, otherwise redo the position
if (!found)
Array[i] = newNumber;
else
i--;
}
return;
}
void ParseAndPrint(int Array[], const int maxsize, const int count)
{
for (int i = 0; (i < count) && (i < maxsize); i++)
{
if (Array[i] < 1000)
cout.width(4);
cout << Array[i] << ' ';
}
cout << endl << endl;
return;
}
void Swap(int& A, int& B)
{
int temp = A;
A = B;
B = temp;
return;
}