Professional Documents
Culture Documents
Title:
Abstract:
Sort.cpp
implementation of SelectionSort.h.
Author:
Date:
Class:
Brian Carlston
2/16/2016
*/
#include "Sort.h"
#include <iostream>
#include <stdlib.h>
void Sort::CoolSort(int input[], int inputlength, int steps[], int stepCount)
{
int j;
//start with the largest step first
for (int i = 0; i < stepCount; i++)
{
j=0;
while(j<steps[i] && j<inputlength)
{
InsertionSort(input, j, inputlength, steps[i]);
j++;
}
}
}
void Sort::InsertionSort(int input[], int startIndex, int length, int step)
{
int temp, j, index;
for (int i = startIndex; i < length; i+=step)
{
j=i-step;
index = i;
//while input[index] is less than the previous value swap them
while(input[index]<input[j] && j>=0)
{
temp = input[j];
input[j] = input[index];
input[index] = temp;
index = j;
j-=step;
}
}
}