/*
Authors:Travis Gadberry
	Patrick Hesser
	Chris Ladewig
Date:	9 Feb 05
Updated:16 Feb 05
File:	BubbleSort.cpp
*/


#ifndef BUBBLESORT_H
#define BUBBLESORT_H
  #include "BubbleSort.h"
#endif

BubbleSort::
BubbleSort() {
  n = 1;
  A = new int[n];
  A[0] = 0;
  sorted = true;
}

BubbleSort::
BubbleSort(int * newArray, int N) {
  n = N;
  A = new int[n];
  for(int i=0; i<n; i++)
    A[i] = newArray[i];
  sorted = false;
  resetIncrements();
}

BubbleSort::
~BubbleSort() {
  delete(A);
}

int *
BubbleSort::
getArray() {
  return A;
}

int
BubbleSort::
getN() {
  return n;
}

bool
BubbleSort::
getSorted() {
  return sorted;
}

double
BubbleSort::
getTime() {
  return time;
}

int
BubbleSort::
getIncrements() {
  return increments;
}

void
BubbleSort::
setArray(int * newArray) {
  delete(A);
  n = sizeof(newArray);
  A = new int[n];
  sorted = false;
}

void
BubbleSort::
sort() {
  clock_t t1, t2;
  t1 = clock();

  for(int i=0; i<n-1; i++)
    for(int j=n-1; j>=i+1; j--)
        if(increments++, A[j]<A[j-1]) {
	  int t = A[j];
          A[j] = A[j-1];
          A[j-1] = t;
        }
  t2 = clock();
  time = (t2 - t1)/CLOCKS_PER_SEC;
}

void
BubbleSort::
setN(int newN) {
  n = newN;
}

void
BubbleSort::
setSorted(bool newSorted) {
  sorted = newSorted;
}

void
BubbleSort::
resetTime() {
  time = 0.0;
}

void
BubbleSort::
resetIncrements() {
  increments = 0;
}

