Okay, I'm back. (you probably saw this coming ya?)
So, the sort function I have written out doesn't appear to be doing it's job. Here is the function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
void selSort(wordList list[], int& elts)
{
int spot = 0;
int idxMin = 0;
int idxMax = elts - 1;
for(int spot = 0; spot < elts - 1; spot++)
int idxMin = spot;
for(int idx = idxMin+1; idx < elts; idx++)
if(list[idx].wordRec < list[idxMin].wordRec)
idxMin = idx;
if(idxMin != spot)
swap(list[idxMin].wordRec,list[spot].wordRec);
else
{
swap(list[idxMin].wordRec,list[idxMax].wordRec);
elts--;
}
}
|
The words in my test file all stayed in the same position...the first word was placed in the last slot and removed, for reasons I do not understand. Any idea as to why this isn't working at all? I'm so close to being done with the project, I just want to be done with it. This is the final part, all I gotta do after this is output it all, which is easy.
Thanks again for the help thusfar, guys.
EDIT:
To clarify: The function is supposed to look at the current word, compare it to the previous word, and then swap them accordingly. Is this possible with string? Should I try to convert the strings to ints? At the end, it checks if the current word is the same as the previous one, and then places the current one up front and removes it if it is. At least that's what it's supposed to do..hmm.
EDIT2:
Oh, almost forgot, here's the function for swap:
1 2 3 4 5 6 7
|
void swap(int x, int y)
{
int temp;
temp = x;
x = y;
y = temp;
}
|