/********************************************************************************************
sortflt.cpp
	Jim Millard
	for CO311

    Sorting utility routines for floating-point arrays

********************************************************************************************/
#include <iostream>
#include <string>
#include <time.h> //for seeding the random number generator

#include "sortflt.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(float 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 newInt = rand() % 10000; //between 0 and 9999
        float newFloat = newInt / 1000.;  //adjust to 0 to 9.999

        //check for duplicates (we don't want any)
        bool found = false;
        for (int j = 0; (j < count) && (j < maxsize); j++)
            if (Array[j] == newFloat)
                found = true;

        //if there were no duplicates, save the number, otherwise redo the position
        if (!found)
            Array[i] = newFloat;
        else
            i--;
        }

    return;
    }

void ParseAndPrint(float Array[], const int maxsize, const int count)
    {
    cout.precision(3);
    cout.setf(ios::fixed);
    for (int i = 0; (i < count) && (i < maxsize); i++)
        cout << Array[i] << "   ";
    cout << endl << endl;

    return;
    }

void Swap(float& A, float& B)
    {
    float temp = A;
    A = B;
    B = temp;

    return;
    }