I'm trying to implement a selection sort function for an array of user inputted string objects. Am I on the right path as far as arguments go. Thanks

void selectionSort(char ARRAY[], int size)
{
int startScan, minIndex, minValue;

for (startScan = 0; startScan < (size - 1); startScan++)
{
    minIndex = startScan;
    minValue = ARRAY[startScan];
    for (int index = startScan + 1; index < size; index++)
    {
        if (ARRAY[index] < minValue)
        {
            minValue = ARRAY[index];
            minIndex = index;
        }
    }
    ARRAY[minIndex] = ARRAY[startScan];
    ARRAY[startScan] = minValue;
}
}
share|improve this question
    
String object or characters? The answer is very different in either case. – quasiverse Sep 19 '11 at 1:28
    
You might want to use the qsort function: cplusplus.com/reference/clibrary/cstdlib/qsort – Radu Sep 19 '11 at 1:32
    
@quasiverse - string object – hart929 Sep 19 '11 at 1:32
    
As far as arguments go? Yes, you are. – Beta Sep 19 '11 at 1:32

You probably want to use the STL libabry and declare the argument as

std::vector< std::string >

then the sort function will work directly, like this

std::vector< std::string > array;
std::sort (array.begin(), array.end());
share|improve this answer

If you are sorting string objects then there's a lot of problems. The code you wrote sorts characters. This:

char ARRAY[]

is an array of characters. These:

char *ARRAY[]
std::string ARRAY[]

are arrays of strings. You will have to change your function appropriately with either of these.

share|improve this answer
1  
so if want to use a string array of characters am I on the right track? – hart929 Sep 19 '11 at 2:03
    
@hyuj String array of characters? If you meant an "array of strings" or a "string array" then yes. – quasiverse Sep 19 '11 at 2:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.