ralphsort.h
//Programmer: Eric Barnes
//Class: CS 53
//Date: 4/7/2014
//File Description: Header file for Ralph's Sorting Algorithm
#ifndef RALPHSORT_H
#define RALPHSORT_H
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
const int LETTERS_RANGE = 26;
const int LETTERS_MIN = 65;
const int WEIGHT_RANGE = 67;
const int WEIGHT_MIN = 12;
const int HEIGHT_RANGE = 25;
const int HEIGHT_MIN = 10;
struct wookie
{
string name;
float weight;
float height;
};
//Description: fills an array with random letters
//Pre: None
//Post: arr[0] <-> arr[size] contain random letters
void init_array(char arr[], const int size);
//Description: fills arr with random wookies
//Pre:None
//Post: arr[0] <-> arr[size] contain wookies with random heights/weights
// and names input by user, prompt for names output to screen
void init_array(wookie arr[], const int size);
//Description: determines if w1 is greater than w2
//Pre: None
//Post: returns true if w1 > w2, false otherwise
bool operator > (const wookie w1, const wookie w2);
//Description: inserts a wookie into an ostream
//Pre: os is connected
//Post: wookies name, height, and weight is inserted into os
ostream & operator << (ostream & os, const wookie wook);
//Description: sorts the given array in ascending order
//Pre: arr[0] <-> arr[size] is data
//Post: elements of arr are sorted in ascending order
template <typename T>
void ralphSort(T arr[], const int size)
{
T temp;
bool iSorted;
for(int i = 0; i < size; i++)
{
iSorted = false;
//finding correct place for arr[i]
for(int j = i; j > 0 && !iSorted; j--)
{
if(arr[j - 1] > arr [j])
{
temp= arr[j - 1];
arr[j - 1] = arr[j];
arr[j] = temp;
}
else
iSorted = true;
}
}
return;
}
//Description: prints contents of an array
//Pre: arr[0] <-> arr[size] contains data
//Post: contents of arr are output to the screen
template <typename T>
void printArray(T arr[], const int size)
{
cout << endl;
for(int i = 0; i < size; i++)
cout << arr[i] << endl;
cout << endl;
return;
}
#endif