/*
  Travis Gadberry
  Patrick Hesser
  Chris Ladewig

  RandomArrayGen.cpp
  21Mar05
*/

#include "RandomArrayGen.h"

using namespace std;

RandomArrayGen::RandomArrayGen(){
 array = (int*)malloc(100);
 n=100;
 type=0;

}

RandomArrayGen::RandomArrayGen(int size, int typeofa){
  n=size;
  type=typeofa;
  genArray();
}

RandomArrayGen::~RandomArrayGen(){}

RandomArrayGen&
RandomArrayGen::
operator=(const RandomArrayGen& o) {
  if(this == &o) return *this;

  delete [] array;

  n = o.n;
  type = o.type;
  for(int i=0; i<n; i++)
    array[i] = o.array[i];

  return *this;
}

int * RandomArrayGen::getArray(){
  return array;
}

vector<int>
RandomArrayGen::
getVector() {
  vector<int> V;
  for(int i=0; i<n; i++)
    V.push_back(array[i]);
  return V;
}

int RandomArrayGen::getN() const{
  return n;
}

int RandomArrayGen::getType() const{
  return type;
}

void RandomArrayGen::setN(int a) {
  n=a;
}

void RandomArrayGen::setType(int a) {
  type=a;
}

void RandomArrayGen::genArray() { 
	srand((unsigned)time(0));
	int a=type;
	int i=0;
	int* array1;
	switch(a) {
    case 0: 
		array1= (int*)malloc(n * sizeof(int));
		for(i=0; i<n; i++){
			array1[i]=i;
		}
		array=array1;
		break;
	case 1:
		array1= (int*)malloc(n * sizeof(int));
		for(i=0; i<n; i++) {
			array1[i]=n-i;
		}
        array=array1;
	    break;
	case 2:
		array1= (int*)malloc(n * sizeof(int));
		for(i=0; i<n; i++){
            array1[i]=rand()%n;
		}
		array=array1;
	}

}

