coolboym99 0 Newbie Poster

So I'm writing a sorting program for my class where we're required to sort three files by Insertion Sort, Shell Sort, and Quick Sort. By the way that it works, I ended up using vectors for all the data, and I've got Everything working now, except for the shell sort. Do you have any advise for what I could do to fix it?


Here's what I've got for it:

void ShellSort::shellSorting()
{
	int increment, start;
	increment = count;
	startTime = clock();
	do
	{
		increment = increment/3+1;
		for(start = 0; start< increment; start++)
			sortInterval(start, increment);
	}while(increment>1);
	endTime = clock();
//	elapsed_clock = endTime–startTime;
	elapsed_time = ((endTime-startTime)/CLK_TCK);

}


void ShellSort::sortInterval(int start, int increment)
{
	int first_unsorted;
	int position;
	int current;
	for(first_unsorted = start; first_unsorted < count; first_unsorted+=increment)
		if(first_unsorted + increment < count)
			if(shellList[first_unsorted] > shellList[first_unsorted + increment])
			{
				position = first_unsorted;
				current = shellList[first_unsorted];
				do
				{
					shellList[position] = shellList[position+increment];
					position+=increment;
				}while(position >0 && shellList[position+increment] < current);
				shellList[position] = current;
			}
}

now I'm pretty sure I understand it, and also as a help, my book said that the Insertion function is basically the basis of the sorting for the Shell sort, and here's what I have for my working Insertion function:

void InsertionSort::insertSorting()
{
	int first_unsorted;
	int position;
	int current;
	startTime = clock();
	for(first_unsorted = 1; first_unsorted < count; first_unsorted++)
		if(insertList[first_unsorted]< insertList[first_unsorted-1])
		{
			position = first_unsorted;
			current = insertList[first_unsorted];
			do
			{
				insertList[position] = insertList[position-1];
				position--;
			}while(position >0 && insertList[position-1] > current);
			insertList[position] = current;
		}
	endTime = clock();
//	elapsed_clock = endTime – startTime;
	elapsed_time = ((endTime-startTime)/CLK_TCK);

}

(Also, as a random side note, my elapsed_clock equation isn't working, and that baffles me too, lol.)