Hi, I'm having troubles with my sorting algorithm that I got from mathbits.com. It does the job very well, however almost too well. This is a sample of what I inputted
{T79_W1, T7_W1, T79_W11, T78_W3, T7_W2, T79_W3, T79_W10, T78_W4, T79_W2}
which comes out
{T78_W3, T78_W4, T79_W1, T79_W10, T79_W11, T79_W2, T79_W3, T7_W1, T7_W2}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
void sort (std::vector<std::string> &ToSort)
{
int flag = 1, ToSortLength = ToSort.size();
int d = ToSortLength;
std::string temp;
while (flag || (d > 1))
{
flag = 0;
d = (d + 1)/2;
for (int k = 0;k < (ToSortLength - d);k+++
{
if (ToSort[k + d] < ToSort[k])
{
temp = ToSort[k + d];
ToSort[k + d] = ToSort[k];
ToSort[k] = temp;
flag = 1
}
}
}
}
|
Sorry if that didn't come out looking so pretty, new to this, plus had to type it out since my code is on a virtual machine.
For a description of what this actually does, see
http://mathbits.com/MathBits/CompSci/Arrays/Shell.htm. I guess this is more a logic problem than anything else but I was wondering if anyone could think of a clever way to sort this out, been staring at it for a while now!
Thank you!