Selection Sort Function Not Working

I am inputting info into my array from a .dat file. I can see the unsort info from the file. When it is time for the selectionSort function to actually sort the array and then display the information I am not getting any thing to work. I am not getting an compiler errors. What am I am missing? I have scoured the internet and haven't been able to figure this out. I am sure it is something simple that I am missing.

// here is my program

#include <iostream>

#include <fstream>

#include <string>

using namespace std;

void displayArray(string[], int);

void readNames(string[], int);

void selectionSort(string[], int);

int main()

{

const int SIZE = 10; // set the array size to 10

string values[SIZE]; // setting the array for string

readNames(values, SIZE); // reading the names

return 0;

}

void readNames(string values[], int num) // read data file into array

{

ifstream dataFile;

dataFile.open("names.dat"); // opening the names file

cout << "Unsorted Names from File:\n"; // reading the names from the names.dat file

for (int count = 0; count < 10; count++)

{

getline(dataFile, values[count]);// reading the name from the file in a loop until all names are listed

cout << values[count] << endl;// outputing the unsorted names

}

dataFile.close(); // close the name file

cout << "Sorted Names from File:\n";

}

void selectionSort(string values[], int SIZE) //sorting the names

{

int startScan;

int minIndex;

string minValue;

for (int startScan = 0; startScan < SIZE; startScan++)

{

minIndex = startScan;

minValue = values[minIndex];

for (int index = startScan + 1; index < SIZE; index++)

{

if (values[index] < minValue)

{

minValue = values[index];

minIndex = index;

}

}

values[minIndex] = values[startScan];

values[startScan] = minValue;

cout << values[minIndex] << endl;

}

}

void displayArray(string values[],int num)

{

{

for (int count = 0; count < 10; count++) // loop to display the names from file in ascending order

cout << values[count] << endl;

system("pause");

return;

}

}]
Topic archived. No new replies allowed.